4

hopefully an easy one here. I have some labels and text fields. Between them, I want some empty labels, which will if needed to be error texts. But when I try to stack view it all, Xcode zooms out and nothing can be seen on the viewController. Anything else I need to change for it to work?

You can see a picture of it here before I hit stack view:

Xcode

The email label and text field are already in stack view, so are passwords, gentag passwords and label/button.

Iman Bahrampour
  • 6,180
  • 2
  • 41
  • 64
Jonas Larsen
  • 378
  • 4
  • 14

2 Answers2

3

This certainly appears to be a bug. I duplicated your issue. I was able to solve it by setting a height/width to each empty spacer label, prior to adding it to my stack view. This doesn't make sense because when you add an object to a stack view it loses all of the constraints it has. None the less it resolved the issue:

enter image description here

Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55
  • The stackview needs to be email label and email text field. i dont know if this changes anything? – Jonas Larsen Oct 06 '17 at 10:39
  • I just tested. It doesn't matter how you configure your stack view. As long as you set a height and width constraint of the empty label before you add it to the stack view, it works. It behaves as it should. – Martin Muldoon Oct 06 '17 at 10:44
  • I just tried, I add contraints to the empty label. But it still does the same. Anything I do wrong? Im using Xcode 8.3.3 if that does anything? – Jonas Larsen Oct 06 '17 at 10:49
  • Jonas. Please remove each stack view you have. Click on the S.V. Then on the Menu Bar select Editor -> UnEmbed. This will remove the S.V. Then add a height/width constraint to each empty label. Then add everything back to your stack view(s) as you like. – Martin Muldoon Oct 06 '17 at 10:51
  • Glad to be of service! – Martin Muldoon Oct 06 '17 at 10:58
0

Sounds like its just an auto layout issue (or lack of). Can be really messy, best to just keep playing around.

As you've already done, I would first put each label and its text field in a horizontal stack view and add constraints.

Then I'd add each of these stackviews to their individual warning labels in a vertical stackview and add constraints.

Finally I would combine all of the stackviews into one vertical stackview!

alextudge
  • 113
  • 6