5

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

froggomad
  • 1,747
  • 2
  • 17
  • 40
  • Does the image view contain an image? If it is empty it might be allocated zero dimensions. – Magnas May 28 '17 at 20:31
  • Are there any constraints between the image view and its containing `UIView`? – rob mayoff May 28 '17 at 21:02
  • There weren't constraints between the two because I overlooked it, but I've pinned the imagview to the uiview now and it still doesn't appear. The image is empty, but is set on tapping the play button. The UIView itself doesn't show either (I'm using it in order to show a static border around the UIImage while the UIImage animates) – froggomad May 28 '17 at 21:17
  • Had to set size constraints on the UIView – froggomad May 28 '17 at 21:23
  • 1
    Just for anyone googling here. With **Catalyst** there are many problems. (As of 2022.) For example, stack views behave weirdly inside table cells. Try moving the app between monitors, and the content of the stack view will often disappear. – Fattie Jul 21 '22 at 12:28

3 Answers3

5

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
Mark Moeykens
  • 15,915
  • 6
  • 63
  • 62
  • I had an imageview that I wouldn't set until runtime.. it would always disappear... on the other hand, setting an image at compile time would display the image correctly. – alasker May 06 '18 at 14:54
  • 2
    BTW, only a height or top/bottom constraint didn't solve the problem for me.. in my case I also had to go with a width constraint – alasker May 06 '18 at 14:56
  • Just add a height constraint – Tuan Pham Jul 08 '18 at 16:08
2

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

swift_dande
  • 45
  • 1
  • 8
0

Setting a Y constraint on the UIView border caused it to appear when hitting the play button, but it grew outside of the screen bounds.

I had to set size constraints on the UIView in order for it to display properly.

froggomad
  • 1,747
  • 2
  • 17
  • 40