Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • replacement of the deprecated sizeWithFont: method in iOS 7

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.21k
    Comment on it

    we all know NSString method sizeWithFont

    [@"abacfe" sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByCharWrapping];
    

    deprecated in iOS 7. So here is the replacement of this method.

    CGSize maximumLabelSize = CGSizeMake(245, FLT_MAX);
    NSStringDrawingOptions options = NSStringDrawingTruncatesLastVisibleLine |
    NSStringDrawingUsesLineFragmentOrigin;
    
    NSDictionary *attributDict = @{NSFontAttributeName: [UIFont systemFontOfSize:11]};
    CGRect rectsize = [@"abcedef" boundingRectWithSize:maximumLabelSize options:options attributes:attributDict context:nil];
    

    if you want to get the height or widht use

    float height=ceilf(rectsize.height);
    float width=ceilf(rectsize.width);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: