Reputation: 761
I'm trying to set my label size to be dynamic, however this current method is deprecated. I know that the correct method is:
boundingRectWithSize:options:attributes:context:
This really doesn't do the trick for modifying the font size along with line break mode.
CGSize expectedLabelSize;
expectedLabelSize = [textLabel.text sizeWithFont:[UIFont fontWithName:@"Ubuntu-Bold" size:14] constrainedToSize:maximumLabelSize
lineBreakMode:NSLineBreakByWordWrapping];
Is there another method that should be used to change the attributes for my label?
Upvotes: 0
Views: 305
Reputation: 17595
Just try this..
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
CGSize labelContraints = CGSizeMake(width, 105.0);//Here I set maximum height as 105 for maximum of 5 lines.
NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
CGRect labelRect = [str boundingRectWithSize:labelContraints
options:NSStringDrawingUsesLineFragmentOrigin attributes:attributesDictionary
context:context];
Note: It will working IOS7+
Upvotes: 1