Search code examples
iosuser-interfaceautolayoutinterface-builderios-autolayout

Setting width constraint to Activity Indicator breaks stackviews?


This is what the view looks like after setting a horizontal stackview between the label and the activity indicator:

enter image description here

This is not the expected output because I want the label and the activity indicator to be close to each other. It looks like the stackview tried to assign similar widths to both subviews.

I tried assigning a 10 width constraint to the activity indicator and it ended up like this:

enter image description here

Here's the left panel:

enter image description here

How do I have a label with an activity indicator to the right of it?

I'm expecting something that looks like this:

enter image description here


Solution

  • This happens, because Stack View inserts constraints with required (1000) priority. What you can do is change Content Compression Resistance Priority of your label and Content Hugging Priority of activity indicator to 1000 (no need in additional width constraint in that case) enter image description here enter image description here