I'm porting one of apps from iOS 6.1 to iOS 7. I'm using a layout where there's a UITextView
that has a fix width, but it's height is based on its contentsize. For iOS 6.1 checking the contentsize.height and setting it as the textview's frame height was enough, but it doesn't work on iOS 7.
How can I then create a UITextView
with a fixed width, but dynamic height based on the text it's showing?
NOTE: I'm creating these views from code, not with Interface Builder.
simple solution -
textView.isScrollEnabled = false
works perfect when inside another scroll view, or tableView cell withUITableViewAutomaticDimension
There are simplier solution, using this method:
UPD: working just for displaying text (isEditable = NO)
My final solution is based on HotJard's but includes both top and bottom insets of text container instead of using 2*fabs(textView.contentInset.top) :
This worked for me for iOS6 and 7:
Use this little function
In iOS7,
UITextView
usesNSLayoutManager
to layout text:disable
allowsNonContiguousLayout
to fixcontentSize
: