-1

I have a UIView that has a subview I want the yellow view to grow only as the length of the label is unfortunately it grows to the maximum width of the screen minus the forced margins i gave it between the white view and the yellow view left and right margins

i've set the content hugging priority to 502 , 501 on the white and yellow view

how do i make this work ?

enter image description here

Lena Bru
  • 13,521
  • 11
  • 61
  • 126

1 Answers1

1

What I have understood from your question is you want your yellow view to have intrinsic content size i.e its size should depend on the size of label.For this follow these steps -

1 .Add following constraints to the yellow view

           a.Center horizontally in container.

           b.Center vertically in container.
  1. Now to the image view add following constraints

           a. Leading and Trailing space with respect to yellow view.
    
           b. Top space with respect to yellow view and Bottom space with respect to label.
    
  2. Now to the label add following constraints

          a. Leading and trailing space with respect to yellow view.
          b. Bottom space with respect to yellow view.
    

This will give you desired result.Now label have leading and trailing space pinned to the yellow view, so as label will grow, yellow view will automatically grow.

You can see the required constraints added in the screenshot.

Ajay Kumar
  • 1,807
  • 18
  • 27