views:

68

answers:

2

How can I know the displayed text in the UILabelView? I have a large text and I am going to have 3 uilabels that represent 3 columns of an iPad App like NYTimes one. When I put the large text in the first column (UILabelView) I need to know how much of the text is displayed there..

If U suggest another solution please let me know. Charly

A: 

What you are asking for is a way to measure text. The iPhone SDK documents a way to find out how big a body of text is, but not how much text fits in a given space. You can use the former to do the latter iteratively.

Look in UIStringDrawing.h for the following method:

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;

Use this method to do a (preferably binary) search on different length substrings of your string until you find a substring that fits a particular height. You have now figured out how much text the first UILabel can display. Repeat for each column.

You could also use CTTypesetter in CoreText, but that is 3.2 forward.

drawnonward
A: 

Thank you drawnonward! I try but... I cannot do it :( This is the scenario: I have a long text.. and 2 columns.. I use Arial of size 10. The columns are in a fixed size. How can I cut that long string to full the 2 columns? I do not need that all the text fit in those 2 columns; I only need to fill the 2 columns .. the rest of the text I will show it in other page...

For a long text that fuction, for a column of 140 width x 234 height give me: CGSize sizeObj = (function here) sizeObj .height = 128 sizeObj .width = 14

I do not understand the picture :(

Thank you in advance! charly