P Paulie87 macrumors newbie Original poster Mar 2, 2014 24 0 Mar 7, 2014 #1 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.
Duncan C macrumors 6502a Jan 21, 2008 853 0 Northern Virginia Mar 7, 2014 #2 Paulie87 said: 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. Click to expand... 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.) Click to expand... 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.
Paulie87 said: 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. Click to expand... 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.) Click to expand... 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.
M mjohnson1212 macrumors member Nov 15, 2007 92 11 Mar 7, 2014 #3 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];
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];