Reputation: 16841
scrollView = [[UIScrollView alloc] initWithFrame:
[[UIScreen mainScreen] applicationFrame]];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(25, 100, 200, 250)];
textView .text =@"long text ";
I will be getting some data of unknown length. to be added to the UITextView
. Sometimes the height of the content of the text might exceed the height of the UITextView
which is 250
(shown above).
How can i increase the height of the UITextView
based on the text i receive ? I would appreciate a sample code?
note: according to my code i am defining the width
and height
of the UITextView
before adding the text to it.
Upvotes: 0
Views: 445
Reputation: 58448
You can use NSString
's sizeWithFont:constrainedToSize:lineBreakMode:
to get a CGSize
struct telling you how big the text will be.
Usage:
CGSize size = [mystring sizeWithFont:[UIfont systemFontOfSize:15]
constrainedToSize:CGSizeMake(200, CGFLOAT_MAX)
lineBreakMode:UILineBreakModeWordWrap];
[myTextView setFrame:CGRectMake(25,100,200,size.height)];
Upvotes: 3