How to convert sizeWithFont to sizeWithAttributes (iOS 7)

How to get the value CGSizefor NSStringin iOS 7 SDK, just want to convert the following lines of code using sizeWithAttributes.

CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
+4
source share
1 answer

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];
+9
source

Source: https://habr.com/ru/post/1533476/


All Articles