开发者

Dynamic expand UITextView

开发者 https://www.devze.com 2023-03-30 08:29 出处:网络
I have UITextView and I want to expand it dynamically. If the text is should scrol开发者_Go百科l I want to expand the view to fit the amount of the text. How can I do that. Thanks When you end the edi

I have UITextView and I want to expand it dynamically. If the text is should scrol开发者_Go百科l I want to expand the view to fit the amount of the text. How can I do that. Thanks


When you end the editing of your text write this.

- (void) textViewDidEndEditing:(UITextView *)textView
{
    CGRect frame = myTextView.frame;
    frame.size.height = myTextView.contentSize.height;
    myTextView.frame = frame;
}


You will have to find the heightof the text you need to contain inside the UITextView (of a particular fixed width) and then set its frame height to that value so that it is not scrollable. You can go through this example to see how exactly to do that.

0

精彩评论

暂无评论...
验证码 换一张
取 消