-2

I've recently started to use UIStackViews auto layout, but keep running into warnings like the ones on the screenshot and I'm not sure how to make them go away.

image image2image3image4image5Any help would be appreciated.

  [1]: https://i.stack.imgur.com/a4aUp.png
  [2]: https://i.stack.imgur.com/U7knK.png
  [3]: https://i.stack.imgur.com/tcPO0.png
  [4]: https://i.stack.imgur.com/Ti3IH.png
  [5]: https://i.stack.imgur.com/PMTrj.png
  [6]: https://i.stack.imgur.com/0LJh7.png
Aaron Owusu
  • 13
  • 1
  • 4

1 Answers1

1

You have many UIViews in your stackView and a UIView does not have any intrinsic height so there is ambiguity.
The stackView basically does not know what height to set for the inner uiview elements and consequently at what y position they will start.

Solution #1:

  • Select the topmost stackView that contains all your other stackViews and in it's Attributes Inspector, change it's distribution to Fill Proportionally.
  • Give X & Y position for the back button

Solution #1


Solution #2:

  • You give a height constraint to each UIView (your backButtonView, titleView, etc.) except for the last one bottomSpace

Solution #2


Besides, you have nested stackViews unnecessarily. Also, you don't have to do everything in a stackView.

The first view looks like you want a top bar with a back button. You should be using a navigationBar with a navigationItem which need not and should not be in a stackView unless your design has a special requirement.

The last view looks like you want to leave space so you have a bottomSpace view in a stackView and both of these are unnecessary.

Solution #3

  • Redesign your layout and simplify it further.
    For your layout, you can make do with a single stackView btw.

As an example, it's not exactly as per your design but near about: Solution #3

Community
  • 1
  • 1
staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
  • Thanks the warnings have disappeared. Really Appreciate the help, and also you're right, some of the stackviews are unnecessary. I will restart with a much simpler design. – Aaron Owusu Feb 16 '18 at 11:59
  • I've decided to go with your first solution on the basis that it works well with the design that I'm after. However when setting constraints to my label I find myself with the following error: http://prntscr.com/ifps18 and when i add the trailing constraint with the greater than or equal relation, i get the following warning: http://prntscr.com/ifpu5e – Aaron Owusu Feb 16 '18 at 18:30
  • @AaronOwusu Are you sure it is the label causing that warning? In your second screenshot, that warning is still there plus a new one. It's a bit difficult to help like this. Basically you need to familiarize yourself with the autolayout engine some more. I will still help as much as I can through comments – staticVoidMan Feb 18 '18 at 05:56
  • Have you got any suggestions as to where i can learn more about autolayout, youtube has some examples but they're not really relevant to the things i want to create. – Aaron Owusu Feb 18 '18 at 16:37
  • @AaronOwusu Understand AutoLayout, it's possibilities & limitations, & then rethink your design and go for it. Try this tutorial: https://cocoacasts.com/welcome-to-auto-layout-fundamentals – staticVoidMan Feb 23 '18 at 05:37