Giulio Colleluori
Giulio Colleluori

Reputation: 1361

Autolayout - Make superview height equal to subview height + constant where subview is textView

I have a UIView and inside the UIView I have a UITextView. The UITextView does not scroll, instead I set it programmatically to its full height with the following line of code :

self.textView.sizeToFit()

Through the interface builder, I set the following constraints for the UITextView , including superView.bottom = textView.bottom + 25 :

Constraints for textView enter image description here

But then this is the result that I get when I run the app :

result

If anybody has any idea how could I fix this to fit the whole 'extended' textView, that would be really appreciated if you could let me know. Thanks in advance.

Upvotes: 0

Views: 743

Answers (1)

Wain
Wain

Reputation: 119021

Use a label instead of a text view. The important difference is that a label has an intrinsic content size where as a text view doesn't (because it's intended to scroll its content). This allows the label to work with the constraint system to display all of the text (without you needing to calculate the size).

If you stay using the text view you should add a height constraint and calculate the required height and configure the constraint appropriately.

Upvotes: 2

Related Questions