简体   繁体   中英

Auto size for text view

I have a text view and 3 buttons on my User Interface. The first button sets the text of the text view to just one line of text. (I also do this in the viewDidLoad ) The second button sets the text of the text view to 3 lines of text. The third button sets the text of the text view to 5 lines of text. The text view's size only fits one line of text. How to change it's size every time I tap a button to fit the text hight?

Note : I am using ios 7.1

Does anyone know how to do this?

UITextView is a subclass of UIView. You can call:

[myTextView sizeToFit];

To ensure that the view resizes to fit the contents as described here:

https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/sizeToFit

You can call:

[myTextView sizeToFit]

In the IBAction that your button is linked to, or the function that you have linked to the button as a selector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM