5

How to get CGSize value for a NSString in iOS 7 SDK, just want convert the below lines of code with sizeWithAttributes.

CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
The Guardian
  • 374
  • 1
  • 7
  • 22
Musthafa
  • 862
  • 3
  • 12
  • 27
  • possible duplicate of [iOS 7 sizeWithAttributes: replacement for sizeWithFont:constrainedToSize](http://stackoverflow.com/questions/19145078/ios-7-sizewithattributes-replacement-for-sizewithfontconstrainedtosize) – BB9z Nov 20 '14 at 07:43

1 Answers1

10

you can try this...

 NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:14]};

[text sizeWithAttributes:attributes]

or

CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
jnix
  • 480
  • 3
  • 10