0

I want to adjust my UITextView dependent on the text size,

CGRect frame = _text.frame;
frame.size.height = (_text.contentSize.height);
frame.size.width = _text.contentSize.width;
_text.frame = frame;

I've tried this code but the problem is that even if there are 5 lines of text it only shows 2 lines (you can scroll for the rest of the text). How do I fix that it just shows 5 lines?

Shinonuma
  • 491
  • 2
  • 8
  • 19
  • 4
    Possible duplicate of [question](http://stackoverflow.com/q/50467/1201377) and it's [answer](http://stackoverflow.com/a/2487402/1201377) – Meera Jun 14 '13 at 12:31
  • why you did not follow the above mention approach! – jamil Jun 14 '13 at 12:58

1 Answers1

3

use this code

UIFont font = _text.font;
CGSize textsize = [_text.text sizeWithFont:font constrainedToSize:CGSizeMake(_text.frame.size.width,999) lineBreakMode: NSLineBreakByTruncatingTail]; 

[_text setFrame:CGRectMake(_text.frame.origin.x,_text.frame.origin.y,_text.frame.size.width, textsize.height)];
Ishu
  • 12,797
  • 5
  • 35
  • 51