Omar Abouabdalla
Omar Abouabdalla

Reputation: 1

SizeWithFont deprecated in IOS7

How to change

CGSize size=[tempStr sizeWithFont:[UIFont boldSystemFontOfSize:17]  constrainedToSize:CGSizeMake(200, 56)];

to make it work with IOS7

Upvotes: 0

Views: 57

Answers (2)

Mayank Jain
Mayank Jain

Reputation: 5754

    CGFloat finalHeight;

    CGSize constrainedSize = CGSizeMake(requiredWidth,9999);

    NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:yourRequiredFont, NSFontAttributeName,nil];

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:yourText attributes:attributesDictionary];

    CGRect requiredHeight = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];

    if (requiredHeight.size.width > requiredWidth) {
        requiredHeight = CGRectMake(0,0,requiredWidth, requiredHeight.size.height);
    }

    finalHeight=requiredHeight.size.height;

Upvotes: 1

Michael Dautermann
Michael Dautermann

Reputation: 89509

You have to use sizeWithAttributes:, using something like:

UIFont *font = [UIFont boldSystemFontOfSize:17.0f];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
CGSize size = [tempStrig sizeWithAttributes:attrDictionary];

Upvotes: 2

Related Questions