Musthafa
Musthafa

Reputation: 862

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];

Upvotes: 5

Views: 7011

Answers (1)

jnix
jnix

Reputation: 480

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];

Upvotes: 10

Related Questions