Hello all,
I have a fixed size UITextView say width and height of 150,150.
The purpose is to display the thought of the day. Please note the size need to remain constant and I cant change it.
Now The length of the thought string varies with respect to thought. What I want to do is change the size of font of the text to make sure it dont show any empty space in UITextView if length is small or it dont show the scroll if its bigger.
So how to vary the font of UITextView according to the length of thought string.
What is wrong with the following code:
What happens is the size of the text in TextView is always 60. That is each line has only one word.
I have a fixed size UITextView say width and height of 150,150.
The purpose is to display the thought of the day. Please note the size need to remain constant and I cant change it.
Now The length of the thought string varies with respect to thought. What I want to do is change the size of font of the text to make sure it dont show any empty space in UITextView if length is small or it dont show the scroll if its bigger.
So how to vary the font of UITextView according to the length of thought string.
What is wrong with the following code:
Code:
CGSize size;
BOOL run=TRUE;
CGSize txtViewSize = self.txt_tipView.frame.size;
while(run){
size = [self.txt_tipView.text sizeWithFont:[UIFont systemFontOfSize: currentSize] constrainedToSize:txtViewSize lineBreakMode:UILineBreakModeWordWrap];
if((size.width<=txtViewSize.width) && (size.height<=txtViewSize.height))
run = FALSE;
else
currentSize--;
}
self.txt_tipView.font = [UIFont fontWithName:@"Helvetica" size:currentSize];//[UIFont boldSystemFontOfSize:12];