Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

RWDevCon 2016 Session 103: Beginning UIStackView

In this session you’ll build your first stack view and learn the true power of easily constructing realistic layouts without Auto Layout constraints.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1304-rwdevcon-2016-session-103-beginning-uistackview

Really excellent, Sam! Thank you. I picked up a lot of little tricks. :ok_hand:

1 Like

Great - glad you appreciated it!

sam

In Xcode 8.0 (8A218a) for the first part where you add the stack view in the cell when you rotate the device the view also shows the detail view on the right side of the screen.

1 Like

Ok it was the Split Screen Contrioller that was causing the split screen on the later ( bigger screens) simulators.

1 Like

Glad you got it sorted… sorry for my late reply :confused:

This is an awesome lesson. I have enjoyed your style of explanation,in the video. One big question that comes up for me is, I have a screen that has the following structure
Top Section
Label
Label Value
Label Value
Middle Section
Label
Label Value
Label Value
Bottom Section
Label
Label Value
Label Value
Centered Button.

I am trying to make the Label Value pairs fill the entire horizontal of any iOS device with text Left justified on the Label and Right Justified on the Value. I have tried Fill, Fill Equally, and Fill Proportionality. (no Luck), I have tried pinning them to the left and right with constraints, no luck I must be missing something very obvious here.

Can you point me toward the right direction? I’d be glad to post the XML of the Storyboard if that would help.

Hi @theapapp

I think to get the effect you desire you should be able to do the following:

  1. Create a horizontal stack view containing 2 labels.
  2. Set the Distribution to Fill.
  3. Select the Label label (i.e. the leftmost label).
  4. Set the Horizontal Content Hugging Priority to 249 and the Horizontal Content Compression Resistance Priority to 749.
  5. Ensure that the width of the stack view fills the width of the containing view. If it’s a child of vertical stack view (which in your case I think it is), set the Alignment property on the parent stack view to Fill. If not, pin the stack view to the edges of the containing view.

I’ve not tried it, but I think that will give you the effect you are after. You might need to change the alignment of the Value label to right aligned, but I don’t think you’ll need to.

Hope that a) works and b) helps :slight_smile:

sam

Thank you for responding… for some reason it is not working… Maybe this will be more clear
I have
Main Stack View (vertical) (Centered Horizontal and Vertical within the overall view)
Then Stack View Vertical 1
Stack View A Horizontal
Stack View B horizontal
Stack View C Horizontal
Then Stack View Vertical 2
Stack View D Horizontal
Stack View E horizontal
Stack View F Horizontal
Then Stack View Vertical 3
Stack View G Horizontal
Stack View H horizontal
Stack View I Horizontal

I can’t stretch the Main Stack View to fill the space, even thought the View Content Mode is Scale to Fit. Within Interface Builder the Width and Height are not able to modified.

I have updated all of the hugging as described above and it still just shows the entire set of stacks in the center of the main view. Any suggestions?

@theapapp

In order to get the stack views to correctly stretch, you need to define the dimensions of the outer stack view. In your situation it’s not enough to centre the outer stack view horizontally and vertically - that just defines its position. You also need to specify its size.

You can do this with auto layout - either providing width and height constraints, or pinning it to some other aspects of the layout. More often than not, you’ll want to pin the leading, trailing, top and bottom edges to the edges of the containing view. Or if you want to keep the horizontally centred constraints, specify the width and height to be the same of the containing view.

If I’ve understood your situation correctly, then that might be enough to solve the problem.

sam

Thanks… That worked, now I need to do more design work :slight_smile:

1 Like

Yay! Good luck :slight_smile:

sam