Is it possible to organize t开发者_高级运维ext into two columns with just a UITextView? If not, how can I calculate the height for a given string of text?
NSString has metric functions such as
sizeWithFont:forWidth:lineBreakMode:
that you will need to use. Actually I usually use sizeWithFont:constrainedToSize:lineBreakMode:
, after creating a CGSizeMake(columnWidth, FLT_MAX)
which is then used for the result also - with FLT_MAX as height, only width is being constrained. The resulting CGSize returned will tell you the actual height.
I think that with that in mind it will be much easier for you to use two UITextViews
and to break the text into two sections.
A single UITextView can only display one column. To get the height, create an offscreen UITextView and then try something like:
myTextView.text = theText;
theTextHeight = [myTextView contentSize].height; // in points
精彩评论