开发者

Two columns of text in UITextView?

开发者 https://www.devze.com 2023-02-09 05:11 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消