Adjusting UIView Height Inside UIStackView Control

john doe picture john doe · Sep 18, 2015 · Viewed 34.2k times · Source

I am using a UIStackView in iOS 9 SDK. The height of the stackview is 44 points. I have a UILabel and UIView inside the StackView as shown below:

enter image description here

Now, I want to make the green view much smaller than 44.. much like 20. How can I do that?

UPDATE: Without the UIStackView I am getting breaking constraints:

[GT.BubbleView:0x14536610]   (Names: '|':UITableViewCellContentView:0x14536fd0 )>",
    "<NSLayoutConstraint:0x146b7300 GT.BubbleView:0x14536610.trailing == UITableViewCellContentView:0x14536fd0.trailingMargin>",
    "<NSLayoutConstraint:0x146c4000 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14536fd0(286)]>"

)

Answer

Alexey Bondarchuk picture Alexey Bondarchuk · Sep 23, 2015
  1. First you need to add UIStackView on the cell enter image description here

  2. Need to add constraints to your UIStackView enter image description here

  3. Adjust your UIStackView enter image description here

  4. Drag&Drop UILabel into your UIStackView enter image description here

  5. Then Drag&Drop UIView into your UIStackView enter image description here

  6. Add green-UIView like subview to pink UIView enter image description here

  7. Now you can add couple constraints to green-UIView enter image description here enter image description here

  8. Now you can run app on simulator or device enter image description here enter image description here

    Notice that I don't added any constraints for UILabel.