NSString *myString=@"This is a dynamic string";// It will probably change after some event happens.
UIFont *myFont=[UIFont fontWithName:@"Helvetica" size:10];
CGSize size = [myString sizeWithFont:myFont forWidth:300 lineBreakMode:UILineBreakModeWordWrap];
Create the CGRect with the size calculated above.
CGRect a=CGRectMake(50, 50, size.width, size.height);
Now you can create your label with size received above.
UILabel *myLabel=[[UILabel alloc]initWithFrame:a];
myLabel.text=myString;
myLabel.font=[UIFont fontWithName:@"Helvetica" size:10];
No comments:
Post a Comment