Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift UIView disappearing from Stack View

I have a label, an Image View, and a button in a vertical stack view. The alignment is set to fill, and the distribution to equal spacing with an offset of 10. On my storyboard, the label appears on top, the image in center, and the button at bottom.

However, when run on simulator or device, the UIView is stripped from the view entirely, so the label appears at the top of the screen, and the button directly below the label.

My only constraints are set on the stack views to the superview

Image View should be centered between label and button

Edit: Forgot to mention the UIImageView is inside of a UIView

like image 534
froggomad Avatar asked May 28 '17 20:05

froggomad


2 Answers

I had a similar problem. My UIView in my UIStackView had only a Width constraint and would disappear at runtime. I found I could make it show up again with either of these options:

  • Add a Height constraint
  • Add a Top and Bottom constraint
like image 65
Mark Moeykens Avatar answered Nov 14 '22 18:11

Mark Moeykens


I was having the same issue with a tableview in a stackview. Added the Height constraint to the view and it worked now everything shows fine

like image 36
swift_dande Avatar answered Nov 14 '22 20:11

swift_dande