Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert sizeWithFont to sizeWithAttributes(iOS 7)

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];
like image 699
Musthafa Avatar asked Mar 26 '14 06:03

Musthafa


1 Answers

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];
like image 107
jnix Avatar answered Nov 07 '22 05:11

jnix