iOS 7 sizeWithAttributes: replacement for sizeWithFont:constrainedToSize
well you can try this :
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:14]};// NSString class method: boundingRectWithSize:options:attributes:context is// available only on ios7.0 sdk.CGRect rect = [textToMeasure boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
This is how I did it:
// Get a font to draw it inUIFont *font = [UIFont boldSystemFontOfSize: 28];CGRect textRect;NSDictionary *attributes = @{NSFontAttributeName: font};// How big is this string when drawn in this font?textRect.size = [text sizeWithAttributes:attributes];// Draw the string[text drawInRect:textRect withAttributes:attributes];
Here's my method to deal with both situations, goes in an NSString
category.
- (CGSize) sizeWithFontOrAttributes:(UIFont *) font { if (IS_IOS7) { NSDictionary *fontWithAttributes = @{NSFontAttributeName:font}; return [self sizeWithAttributes:fontWithAttributes]; } else { return [self sizeWithFont:font]; }}