Author Topic: Why is Embed in Stack doing this  (Read 6654 times)

lennyeiger

  • Newbie
  • *
  • Posts: 11
    • View Profile
Why is Embed in Stack doing this
« on: July 26, 2016, 11:09:47 PM »
I have 7 rows of labels on my view controller. There are 4 columns in each row. The first column is a typed-in label, for what is in the row, and the remaining 3 contain values I have passed in. It all works well.

I thought I would try the Embed in Stack feature and I have been fighting with it for hours. When I select a row, and select Embed in Stack View, or click the icon for same, it creates a huge rectangle. I have tried lots of things, the only clue I discovered is that on the Sizes Inspector, it adds a -1,000,000 to the X values. I did try clearing constraints before pressing the Stacks button..

What am I doing wrong?

TIA

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: Why is Embed in Stack doing this
« Reply #1 on: July 28, 2016, 08:35:33 AM »
Hi lennyeiger,

Without seeing your project Iím not exactly sure what youíre seeing, but hereís my best guess.  You said, "When I select a row, and select Embed in Stack View, or click the icon for same, it creates a huge rectangle.  It sounds like youíre on the right path to setting up your stack views.  In your case, you have 4 labels per row, so I would select all 4 labels in a row and then embed those 4 labels in a stack view.  Then, do the same for each row, so in the end youíll have 7 stack views total (1 for each row.)  You mentioned that it creates a huge rectangle.  After creating the stack view, you may need to resize it so it fits inside the area you need it to fit in.  Also, donít forget to set constraints on each stack view. I hope that helps.


Angelina
Oak Leaf Enterprises, Inc.

lennyeiger

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Why is Embed in Stack doing this
« Reply #2 on: July 31, 2016, 06:45:41 PM »
Here's what happened. I added all sorts of constraints using the add suggested constraints. When I removed all of them and had only 2 constraints per UILabel, it accepted being installed in a Stack. (select a row, press the Stack button). I succeeded in most of it... then I realized that I set them up to be equally spaced vertically and I didn't want that. So I need to get one level more complex... deleting the last Stack wrapper turned out to be more than Xcode could handle... so I reverted to a backup. At the moment, I think I am on the right path... After hours and hours of trial and error... I am starting to understand the layout process.

Having only 2 layers of undo proved to be a real difficulty, wondering if there is some preference where one can add more... or utility.

Finally, I noticed that there are Horiz and Vert Stack Views that one can pull out from the Object Library and I and unclear whether I should have built things using those in the first place. Been looking back thru the books ai have and they don't often use all the things in the Object Library, just a couple of them - so I have no context with which to make this decision... 

TIA

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: Why is Embed in Stack doing this
« Reply #3 on: August 02, 2016, 05:18:39 PM »
Hi lennyeiger, 

Itís good to hear youíre on the right path.  Usually, hours and hours of trial and error will do that.  Itís a great learning process and the best way I personally learn myself. 

You mentioned, "deleting the last Stack wrapper turned out to be more than Xcode could handle... so I reverted to a backup.Ē  You can easily remove a stack view (unembed the views in it) by selecting the stack view and then while holding the Option key down, click the Stack button and then choose the ďUnembedĒ option.

Also, the horizontal and vertical stack views (UIStackView object) that you get from the Object Library is useful for cases where you donít have any existing views in your Storyboard scene and youíre starting to build your views from scratch.  So, you would start by simply dragging and dropping either the Horizontal or Vertical Stack View from the Object Library onto your scene.  Then, you can drag and drop your views onto that stack view.  If, however, you already have existing views in your storyboard scene, you probably donít want to drag a UIStackView object onto your scene from the Object Library.  Youíd be better off wrapping your existing views in a stack view by selecting them and then clicking the Stack button at the bottom of Interface Builder and embedding them in a Stack View like that.  They both create Stack Views.  Whether you use one or the other will depend on whether you have existing views or not.


Angelina
Oak Leaf Enterprises, Inc.

lennyeiger

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Why is Embed in Stack doing this
« Reply #4 on: August 02, 2016, 09:48:15 PM »
Thanks, this is helpful.

Had another question, but I removed, answered my own...
I had labels of dissimilar width in a horizontal line, and they went nuts... when embedded. I had to put one set of labels in one stack, and the other in the other, then wrap a Stack around them...
« Last Edit: August 03, 2016, 09:12:23 PM by lennyeiger »

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: Why is Embed in Stack doing this
« Reply #5 on: August 04, 2016, 10:50:27 PM »
I'm glad I was able to help and also glad to hear that you answered your other question about the labels.  See...persistence and dedication pays off :)  It sounds like you're making great progress!


Angelina
Oak Leaf Enterprises, Inc.