Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString sizeWithFont: for multiple lines?

Is there an equivalent to NSString's sizeWithFont: method that can be used for calculating the height of text in a UITectView for a given width? All of the methods from NSString only operate on a single line from what I can tell.

like image 410
Jumhyn Avatar asked Feb 05 '11 19:02

Jumhyn


1 Answers

From Apple's reference for these NSString methods, you could use -sizeWithFont:constrainedToSize: or -sizeWithFont:constrainedToSize:lineBreakMode: for "Computing Metrics for Multiple Lines of Text".

CGSize size = [theString sizeWithFont:font
                    constrainedToSize:CGSizeMake(width, 100000)];
return size.height;
like image 153
kennytm Avatar answered Sep 20 '22 14:09

kennytm