Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Paulie87

macrumors newbie
Original poster
Mar 2, 2014
24
0
Code:
CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(_pageSize.width - 2*20-2*20, _pageSize.height - 2*20 - 2*20) lineBreakMode:UILineBreakModeWordWrap];

How would this be replaced in iOS7

Thanks.
 
Code:
CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(_pageSize.width - 2*20-2*20, _pageSize.height - 2*20 - 2*20) lineBreakMode:UILineBreakModeWordWrap];

How would this be replaced in iOS7

Thanks.

The docs are your friend. If you look up the method sizeWithFont:constrainedToSize: in Xcode, it says:

(Deprecated in iOS 7.0. Use
Code:
boundingRectWithSize:options:attributes:context:
instead. See also UILabel as a possible alternative for some use cases.)

So then you should go consult the docs on the method
Code:
boundingRectWithSize:options:attributes:context:

And if you are unable to figure out how to use the new method, Googling it reveals some very promising info.
 
Check out on NSString in NSStringDrawing.h

Code:
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context

You can use NSMutableParagraphStyle to take in the lineBreakMode and you can create a dictionary with the font you want to use and the paragraph style.

Code:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = lineBreakMode;
NSDictionary *fontAtts = @{NSFontAttributeName : font, NSParagraphStyleAttributeName : paragraphStyle};

A sample call on an NSString would be:

Code:
[string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:fontAtts context:nil];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.