Beginning Auto Layout - Part 3: Section 1: Stack | Ray Wenderlich

Create your first stack view and learn about some basic properties to adjust the layout.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4538-beginning-auto-layout/lessons/3

@catie Can you please correct the warnings statement. Its not Xcode bug rather its because of no horizontal constraint set to the stackView.

That makes sense. If it’s not an Xcode bug, an acknowledgement in the comments would be appreciated.

How can I increase the button height for buttons inside the stack view?

I changed the height of the button prior to adding to the stack view. apparently this cannot be changed once inside the stack view it appears.

Can I create a horizontal stack view which has two items, one left aligned text, and a right aligned image?

Untitled1

@catie Can you please help with this when you get a chance? Thank you - much appreciated! :]

Would appreciate a response to this question. thanks.

  1. set stack view to horizontal
  2. set the auto layout margins all to 0 with “constrain to margins” selected
  3. for the image, choose “aspect fill”
  4. for stack view attributes, remain all the default value
  5. For UILabel, decrease 1 for its horizontal Content Hugging Priority
    Done

This kind of worked, but scales the image to the stack height. I instead tried "Aspect “Fit” on the image and set the image height/width constraints to 25 (size of my png image), but a layout error persisted. I then set height to >= 25 and errors was rid, though uncertain if this is proper approach. It appears to simulate proper on the various devices. Let me know if there is a better approach.

HI
can you help me please, when i will do Size to fit Content my button image make very big left, right, top and buttom,
but if i see on the video it it is like hugging the button text.
also if i change the size again and put it in stack view it change again,
help me please

@catie Do you have any feedback regarding this? Thank you - much appreciated! :]

First of all, thanks for a great tutorial on auto-layout and stack views. I have a question and an “issue” with stack views. I truly hate fighting with auto-layout and stack views and your tutorial has helped quite a bit.

Question
I noted somewhere in these forums about an Xcode bug that will not let you add a blank label to a stack. I reported this to Apple and they informed me that they were already aware of this. Does anyone know when this will be corrected?
I have an app that uses labels and I have to add text to them to keep them stable. Fortunately, the user will never see this mess because when she flips to the view in question my code populates these labels before she ever sees them. Regardless, it would be great if Apple would correct this.

My Issue
The following image shows six rows of textfields and labels embedded in a stack view whose spacing is set to 20.

For some reason there is a wide gap between the first and second rows in the stack view. Each row is embedded in its own stack and then added to the main stack view. This looks as it should in IF, but not on the simulator or a device. The main stack view is constrained to the main view as well.

Does anyone have any idea how to eliminate this gap?

Thanks!

I am tyring to use “Size To Fit” option but its sizing to fit the button image (that I downloded from the materials). Its sizing to fit the height of the button as well. Its not working the way you showed in the video. i.e. just sizing the width as per the text. Any idea why this is happening?
Please see the screencast of whats happening exactly here - Screencast