Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize TEXT to Fit on UITextView

Is there possible to resize text to fi my UITextView? I tried something like:

  if (_myTextView.contentSize.height > _myTextView.frame.size.height)
{
    _myTextView.font = [_myTextView.font fontWithSize:25];
}

This resizing text very well, but i have some lines of text which are longer and then i need to decrease my font size.

like image 759
iDev_91 Avatar asked May 28 '13 00:05

iDev_91


1 Answers

Try the same idea iteratively ...

CGFloat fontSize = 25.0;
_myTextView.font = [_myTextView.font fontWithSize:fontSize];

while (_myTextView.contentSize.height > _myTextView.frame.size.height && fontSize > 8.0) {
    fontSize -= 1.0;
    _myTextView.font = [_myTextView.font fontWithSize:fontSize];
}
like image 178
danh Avatar answered Oct 19 '22 07:10

danh