Nikunj Jadav Nikunj Jadav - 1 year ago 84
Objective-C Question

iOS : How can I set frame of UILabel according to its text?

I want to develop a functionality that to set frame of

according to its text means when text is change its frame is change? If yes, then please share any link or any idea to develop this.

Thanks in advance.

Answer Source

If you want to know needful height for some width you can use the code below:

NSString *yourString = @"My great text o0";
CGSize s = [yourString sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
// s.height is your your height

For more information read here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download