Reputation: 409
I have to determine that if a UILabel has text that fits the size. I can use boudingRectWithSize:options:attributes:context but I cannot explicitly set the number of line. In the deprecated method, I can only set line break mode. Does any one know how to get the size of some text in a label if the number of line is determined (say label.numberofline = 2)?
Upvotes: 0
Views: 109
Reputation: 6192
Easy
CGRect frame = [text boundingRectWithSize:CGSizeMake(label.frame.size.width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : label.font}
context:nil];
CGSize size = frame.size;
NSLog(@"Size of frame %@", NSStringFromCGSize(size));
Upvotes: 1