Alex Rivera | Logout

How to adjust and make the width of a UILabel to fit the text size?

Asked 2010-11-04T07:54:28.927
56

In my project, there is a UILabel with text. The font size is 16pt. The text contents are changed depending on different cases. I hope it can automatically adjust the width of UILabel to fit the total width of texts without stretching.

Is it possible?

Edit
Report

1 Answer

14
NSString *txt1=@"I am here.";
CGSize stringsize1 = [txt1 sizeWithFont:[UIFont systemFontOfSize:14]]; 
[label setFrame:CGRectMake(x,y,stringsize1.width,hieght)];
[label setText:txt1];
answered 2012-11-21T08:36:18.103

Your Answer