How do I return cgsize multiline text from the new IOS 7 method Sizewithattributes?
I think it's going to produce the same result for sizewithfont:constrainedtosize.
NSString *text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu urna quis lacus imperdiet scelerisque a nec neque. Mauris eget feugiat augue, vitae porttitor mi. Curabitur vitae sollicitudin augue. Donec id sapien eros. Proin consequat tellus in vehicula sagittis. Morbi sed felis a nibh hendrerit hendrerit. Lorem ipsum dolor sit."CGSize textSize = [text sizeWithAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:16.0] }];
This method produces only the height of a single line of text.
Workaround 1:
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, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
Ways to label multiple lines in IOS