iOS 7 deprecated code

Discussion in 'iOS Programming' started by Paulie87, Mar 7, 2014.

  1. Paulie87 macrumors newbie

    Joined:
    Mar 2, 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.
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    The docs are your friend. If you look up the method sizeWithFont:constrainedToSize: in Xcode, it says:

    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.
     
  3. mjohnson1212 macrumors member

    Joined:
    Nov 15, 2007
    #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];
     

Share This Page