ixchi
ixchi

Reputation: 2389

Xcode expects UILabel in stack view to have greater height than it is

I am trying place two identically sized sets of a UILabel directly above a UITextField on a UIView. I figured that this would be an excellent use of stack views.

Here is a screenshot of my elements

However, for some reason, Xcode seems to expect that the UILabel will be much taller than it should be and results in warnings about the layout.

Here are the warnings

With the UILabel selected, you can see the outline. You can also see this same sized outline on the other UILabel too, and when selecting the stack view elements it also shows the larger area. When clicking on the UITextField, the outline is shown to begin where the outline from the UILabel ends. Using the 'Resolve Auto Layout Issues' to 'Update Frames' will make the stack view expand outwards to match the size of the outline, however it instantly jumps back to the original size.

Gold highlight around an area much larger than it should be

Am I misusing or have I misconfigured the stack views? Or is there some other issue going on?

I am using Xcode 7.3 build 7D111g.

Upvotes: 3

Views: 4782

Answers (1)

Irfan
Irfan

Reputation: 5130

This is because your label is filling the stackview.

Don't give height constraint to stackview. Just add the following two constraints to top stackview

  1. Top space
  2. Center horizontally in container

enter image description here

Stackview will get its height from its content.

Check this updated GIF :

enter image description here

All warning get finished.

Hope this can help.

Upvotes: 2

Related Questions