What me actually doing:-
lbl1= [[UILabel alloc] init];
lbl1.frame=CGRectMake(10, 10,90, 40);
lbl1.textColor=[UIColor blackColor];
lbl1.text=#"Definitions";
lbl1.font = [UIFont boldSystemFontOfSize:16.0f];
UILabel* finalLabel=[[UILabel alloc] init];
finalLabel.frame=CGRectMake(100, 10,90, 40);
finalLabel.text=[NSString stringWithFormat:#"%#:,The following terms shall have the described meaning:",lbl1];
finalLabel.font = [UIFont fontWithName:#"Helvetica" size:14];
finalLabel.numberOfLines=2;
[self.view addSubview:lbl1];
[self.view addSubview:finalLabel];
Didn't get the proper result of final label
it print:- Definitions
UILABEL:0X68640;frame(10,10,90,40);text='Definition',CliptoBound=YES;Userintraction......
You mean partially bold in a single UILabel. right?
You should check this ONE
Check out with below urls:
Custom Label 1
Custom Label 2
It will be helpful to you and your functionality can be achieved.
Cheers!
In my iphone app. I want to change the text size in a label when clicking a button
Create UILabel
self.lbl=[[UILabel alloc] initWithFrame:CGRectMake(135, 290,200,35)];
self.lbl.backgroundColor=[UIColor clearColor];
NSString *str=[NSString stringWithFormat:#"%.f",[self.slider value]];
[self.lbl setFont:[UIFont fontWithName:#"Arial-BoldMT" size:16]];
self.lbl.text=str;
[self.View addSubview:self.lbl];
Change size of text of UILabel when tapped UIButton
-(IBAction)ButtonPressed:(id)sender
{
[self.lbl setFont:[UIFont fontWithName:#"Arial-BoldMT" size:25]];
}
Here is how to change the font size at runtime....
yourLabel.font=[UIFont systemFontOfSize:14];
-(IBAction)changeFontOfLabel:(id)sender
{
[self.lebelObject setFont:[UIFont fontWithName:#"American Typewriter" size:18];
}
and also write the proper font name . check here for a list of fonts
I have a very long string which is something like that below...
[[sqrt(221)-10,-sqrt(221)-10],[11,11]],[[rootof([[474368400,237184200,-125944810200,258530778000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)+rootof([[409681800,9099248400,-99876110400,-1875803589000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*3,rootof([[-3439170900,-50638826700,864180632700,9670592794500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)+rootof([[1477010700,22974524100,-369910322100,-4442729593500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*3],[rootof([[474368400,237184200,-125944810200,258530778000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*2+rootof([[409681800,9099248400,-99876110400,-1875803589000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*4,rootof([[-3439170900,-50638826700,864180632700,9670592794500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*2+rootof([[1477010700,22974524100,-369910322100,-4442729593500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*4]],[sqrt(sqrt(221)+15),sqrt(-sqrt(221)+15)]
How can i display the whole thing in a UILabel with more than one lines (0)?
Also, although there are no linebreaks ("\n") in the string, the result is displayed like below....
[[sqrt(221)-10,-sqrt(221)- 10],[11,11]],[[rootof([[474368400,2 37184200,- 125944810200,258530778000],[1, 0,- 472,884,42215]])/(sqrt(221)*78270
Any help?
PS I could upload an image but i am not allowed beacause i am a new user...
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
set the UILabel as a multiline
MyLbl.numberOfLines = xxx;
if you have not enough space for set the UIlabel then also set the textView As an not editable property:
Mytxt = [[UITextView alloc]initWithFrame:CGRectMake(xx.0, x.0, xx.0,xx.0)];
Mytxt.transform = transform;
Mytxt.adjustsFontSizeToFitWidth = YES;
Mytxt.textColor = [UIColor blackColor];
Mytxt.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[Mytxt setFont:[UIFont fontWithName:#"Arial" size:xx.0]];
Mytxt.backgroundColor = [UIColor clearColor];
Mytxt.delegate = self;
Mytxt.userInteractionEnabled=YES;
Mytxt.editable=NO;
i hope you get the answer.
You can use UITextView with auto size with non editable mode instead of UILabel (or)
CGSize labelSize = yourString sizeWithFont:cellFont
constrainedToSize:CGSizeMake(190.0f, MAXFLOAT); lineBreakMode:UILineBreakModeWordWrap];
This labelsize will dynamically define the label height you can assign to your label
try this code
NSString *yourString = #"[[sqrt(221)-10,-sqrt(221)-10],[11,11]],[[rootof([[474368400,237184200,-125944810200,258530778000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)+rootof([[409681800,9099248400,-99876110400,-1875803589000],[1,0,-472,884,42215]])";
UILabel *lblNameDesc=[[UILabel alloc] initWithFrame:CGRectMake(55, 10, 250, 21)];
[lblNameDesc setNumberOfLines:0];
lblNameDesc.text=yourString;
[lblNameDesc setBackgroundColor:[UIColor clearColor]];
[lblNameDesc setTextColor:[UIColor colorWithRed:64.0/255.0 green:64.0/255.0 blue:64.0/255.0 alpha:1.0f]];
[self.view addSubview:lblNameDesc];
// [lblNameDesc release];
[lblNameDesc sizeToFit];
supoose your string is. make your fond and width what ever you want:-
NSString longString = #"dsjkghsdkjnfgvsdjgsl,v.........................";
CGSize maximumLabelSize = CGSizeMake(200,MAXFLOAT);
CGSize expectedLabelSize = [longString sizeWithFont:[UIFont fontWithName:#"Aial-BoldMT" size:15.0] constrainedToSize:maximumLabelSize
lineBreakMode:UILineBreakModeWordWrap];
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, expectedLabelSize.height)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 0;
myLabel.text = longString ;
may this will help you
Try This...
textLabel.lineBreakMode = YES;
textLabel.numberOfLines = 10; // or many that you need...
You want UILineBreakModeCharacterWrap if you want your text to be evenly distributed along several lines (so it doesn't try to break at work boundaries).
I have a UILabel which has UILabel attached to it. I add NSString value to it and each time for each cell after the text is over, it appends three dots to the end of the text file.
I am not sure why would I get that. Does any body have faced the similar problems:
Here I define my UILabel:
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
// set the label
label1.backgroundColor = [UIColor clearColor];
label1.font = [UIFont boldSystemFontOfSize:14];
label1.adjustsFontSizeToFitWidth = NO;
self.labelView1 = label1;
[self.contentView addSubview:label1];
[label1 release];
And I add the text as following.
labelView1.text = title;
labelView1.adjustsFontSizeToFitWidth = NO;
If you don't want the label to append '...' when string does not fit label's size set label's lineBreakMode property to UILineBreakModeClip:
label1.lineBreakMode = UILineBreakModeClip;
The problem is that the text is too long to fit the label and you've called
label1.adjustsFontSizeToFitWidth = NO;
which means the text will not be scaled down to fit.
With a width of 15, you can barely fit one letter of font size 14. Make the label bigger or size to fit (or both).
I have a long text string (including \n newline characters) that I feed into a UILabel for display. The UILabel is dynamically set up to provide sufficient space for the text.
My code looks like this:
myText = [NSString stringWithFormat:#"%#some text: %# \n \n %#", myText, moreText1, moreText2];
NSLog(#"%#", myText);
myLabelSize = [vLabelText sizeWithFont:[UIFont fontWithName:#"Helvetica" size:(15.0)] constrainedToSize:cMaxLabelSize lineBreakMode:UILineBreakModeWordWrap];
UILabel *lBody = [[UILabel alloc] initWithFrame:CGRectMake(cFromLeft, vFromTop, vLabelSize.width, vLabelSize.height)];
lBody.font = [UIFont fontWithName:#"Helvetica" size:(15.0)];
lBody.lineBreakMode = UILineBreakModeWordWrap;
lBody.textAlignment = UITextAlignmentLeft;
lBody.backgroundColor = [UIColor cyanColor];
[myScrollView addSubview:lBody];
lBody.text = vLabelText;
My problem is that the text does not wrap, but truncates after the first line. The \n newlines are ignored.
Just found the problem, my numberOfLines was still at 1. After setting it to 0 it works fine.
May be it will be useful - since some lines are deprecated now
lBody.lineBreakMode = NSLineBreakByCharWrapping;
lBody.textAlignment = NSTextAlignmentLeft;
and of course - lBody.numberOfLines should be more than 1(1 is default value)