Mason
Mason

Reputation: 7103

Transition from sizewithFont:constrainedToSize:lineBreakMode: for iOS 7 not behaving as expected

I'm trying to get rid of functions that have been deprecated in iOS 7, and I'm running it something that I don't understand. Here's the code I have right now:

CGFloat titleHeight = [[object name] sizeWithFont:[UIFont fontWithName:@"Abel" size:24.0f] constrainedToSize:CGSizeMake(170.0f, 200.0f) lineBreakMode:NSLineBreakByWordWrapping].height;
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
CGFloat titleHeight2 = [[object name] boundingRectWithSize:CGSizeMake(170.0f, 200.0f) options:0 attributes:@{NSFontAttributeName: [UIFont fontWithName:@"Abel" size:24.0f], NSParagraphStyleAttributeName: paragraphStyle}  context:nil].size.height;

For some reason, titleHeight and titleHeight2 end up being different values, and I can't figure out why. Any ideas? Thanks!

Upvotes: 2

Views: 119

Answers (1)

Dheeraj Vepakomma
Dheeraj Vepakomma

Reputation: 28767

The documentation says:

To correctly draw and size multi-line text, pass NSStringDrawingUsesLineFragmentOrigin in the options parameter.

Have you tried that?

Upvotes: 2

Related Questions