Reputation: 2050
I have a a UITextView
populated with a paragraph of text with variable height at runtime.
At runtime, how do I adjust the height of UITextView
to the height of a variable number of lines (not necessarily equal to the number lines in the paragraph of text)?
For example:
UITextView
to the height of 2 lines of text for some cases of text, thenUITextView
to the height of 5 lines of text for other cases of text (with a scroll-bar to scroll for the other lines as is default behavior)The analogue in CSS would be to set the view height to 2em
if the text is "small", or to 5em
if the text is "large", or in Android setting maxLines
on a TextView
at runtime.
Upvotes: 0
Views: 129
Reputation: 1377
you can use autolayout. first you create a height constraint for your UITextView. then you outlet this constraint to your controller. then you can manipulate height from controller anytime you like.
@IBOutlet weak var heightConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
heightConstraint.constant = 200 // or something else
}
Upvotes: 1