tags:

views:

48

answers:

1

Hello,

I have a fixed size UITextView whose text keeps varying. I want to display the text in a fashion that user dont need to scroll and still he can see the whole text. Also if the text is very short then, it will acquire the whole TextView to make sure user dont see an empty space.When I say the text keeps varying means the length keeps varying.

So as the size is fix and text is varying I know I need to change the size of font for the text. But how to find such an accurate font which will acquire the whole UITextView and avoid scrolling.

I tried using sizeWithFont but it doesnt work. Any kind of help specially with code is appreciated.

Thanks.

A: 

Have you thought of using UILabels, with its automatic font sizing to make the text fit a certain rect?

mahboudz
Well, what about the number of lines. Like I dont want to have control over them, does it set the no of lines automatically. Becoz I need to have the frame of 150 X 150
rkb
Also After a minimum font I do want to have it scrolled.
rkb
You could set the number of lines to 0 to let it handle the number of lines. But no, if you will eventually want scrolling, then you have to stick to UITextView. In that case, you will have to play with '- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode'
mahboudz
Yes I tried doing it, but its not working.
rkb
What do you mean by it is not working? It is only going to give you a CGSize that you then use to resize your TextView. Is it giving you the wrong size? I use CGSize size = [floatingLabel.text sizeWithFont:floatingLabel.font minFontSize:20 actualFontSize:for my labels.
mahboudz