Illep
Illep

Reputation: 16851

Adding a UITextView and scrollview

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? Later i need to add this to a UIScrollView (i know how to add to a scrollview), but again i don't know how to increase the height of the scrollview. Can someone help me code this ?

note: according to my code i am defining the width and height of the UITextView before adding the text to it.

Upvotes: 0

Views: 323

Answers (2)

Bruno Domingues
Bruno Domingues

Reputation: 1015

Set the size of textView equal to it's contentSize. The scrollView you have to set it's contentSize equal to the size you want.

Upvotes: 0

Mark Adams
Mark Adams

Reputation: 30846

UITextView is a subclass of UIScrollView. When the text content grows larger than the frame of the text view, the content will automatically begin to scroll. There is no need to embed a UITextView in a UIScrollView because it already is one (and more!).

Upvotes: 1

Related Questions