How high and wide will NSString write?

How can I determine how large the NSString area will occupy, i.e. using:

[string drawAtPoint:p withAttributes:nil];      

Ideally, I need to do this before drawing it so that I can highlight the "areas" in which lines are drawn accordingly.

+3
source share
2 answers

You can use the message -[NSString sizeWithAttributes:].

+3
source

You can use sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:. This is an add-on NSStringprovided by UIKit(look for "NSString UIKit Add-ons" in the docs).

+3
source

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


All Articles