Search code examples
autolayoutconstraintsuitextviewuinavigationitem

UITextView doesn't appear after adding 4 edge constraints


1a. I had issues with conflicts being reported so I set a Key Path named translatesAutoresizingMaskIntoConstraints in User Defined Runtime Attributes to false (or 'unchecked' checkbox).
1b. Redundancy with (1a): I have self.view.translatesAutoresizingMaskIntoConstraints = false; in the viewDidLoad method.
2. I checked what the storyboard looks like with different devices and they all present the textView in the correct position. See image.
3. Scientific method: without changing anything else in the project, adding constraints causes the issue. Removing them allows for a visible textView, however, it obviously no longer resizes to fit the other devices.
4. I have attempted using constraints both with Safe Area and without.

enter image description here

If I simply added constraints for the top, bottom, left side, and right side (all 0) shouldn't the view at least be stretched out and visible?

Update View Debug Image

The purple (purple means thread-related?) warning says Position and size are ambiguous for UIView. enter image description here

Update 2, UITextView smaller than UIView

The following happens when Safe Area is used and when it isn't used. Notice the white strip across the top and bottom which are part of the UIView, but not part of the UITextView. enter image description here

Update 3

I made some progress. I removed the top and bottom bar from most views, but the bottom bar still shows up in the 'output' view controller that I've been focusing on, however, the top one is gone! I had to uncheck 'Extend Edges Under Top Bars' and 'Extend Edges Under Bottom Bars'


Solution

  • Your problem is quite simple so I'm posting an answer rather to continue commenting. Don't do this self.view.translatesAutoresizingMaskIntoConstraints = false;

    You only set a specific view's translatesAutoresizingMaskIntoConstraints to false when you're doing constraints programmatically. Since you're making your layout in Storyboard, you do not have to do that especially in your superView (self.view).

    About your constraints problem, you can clear all your constraints first and then re-add the constraints.

    Clearing constraints

    enter image description here

    Adding constraints to top, bottom, leading, and trailing. Uncheck constrain to margins

    enter image description here

    Now you should be able to see your UITextView, compare your constraints to mine.