Search code examples
iosxcodeautolayoutuistoryboard

UITextView disappears when AutoLayout Constraints added


I've added a couple of screens to my app and in testing the screens were too large for iPhone5 so I've added some constraints to the three TextViews to help them re-size. The UIView sizes okay as does the first TextView1, I've added the constraint set up views below

enter image description here

UIView constraints

enter image description here

UITextView (1) constraints

The other two TextViews are proving really difficult to place. Without constraints they sit nicely where they were designed but as soon as I add constraints they disappear. I've added their constraints which are pretty much the same as TextView1 the only difference being that TextView1 has it's top pinned to the SuperView whereas the other two are pinned to each other.

enter image description here

UITextView (2) constraints

enter image description here

UITextView (3) constraints

Please can someone tell me where I am going wrong.


Solution

  • Your problem is in the width and height constraints to superView , you have to change the multiplier of these constraints as according to it , every textView fills the entire screen , or at least to the height constraint , BTW if you set leading and trailing to superView then no need for the width constraint as it will cause a conflict because of the leading & trailing margins , so

    1- Remove width constraint

    2- Change multiplier of height constraint by clicking it to value less than 1 which means full screen height

    BTW: I think UIStackView is perfect for your current case