Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How high and wide will NSString write?

How do I work out how much large an area drawing an NSString will occupy, i.e. by using:

[string drawAtPoint:p withAttributes:nil];      

I ideally need to work this out before its drawn so I can space out the "areas" in which the strings are drawn appropriately.


2 Answers

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

like image 176
arul Avatar answered Feb 28 '26 18:02

arul


You can use sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:. It's an addition to NSString provided by UIKit (look for "NSString UIKit Additions Reference" in the docs).

like image 39
pgb Avatar answered Feb 28 '26 17:02

pgb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!