Re: Auto Layout Question

2017-05-24 Thread Quincey Morris
On May 24, 2017, at 08:52 , Dave  wrote:
> 
> Maybe I am going about this in the wrong way? 

Using stack views seems like the hard way. Why can’t you apply constraints 
directly to the 4 views? I’d suggest adding constraints to the labels to center 
them over their graphic views, with a fixed vertical spacing. Then apply 
constraints to the graphic views for aspect ratio, and to use the available 
height or width of the parent view to place them side by side with appropriate 
spacing. If this unit of 4 views needs to be an element of a larger layout, you 
might choose to embed them in a custom view which has its own constraints 
relative to the larger layout.

Stack views just aren’t very good for situations where you need cross-“cell” 
constraints. Stack views work best (and I wish the documentation would say 
this) when you *don’t* add constraints, but rely on the built-in behavior to 
lay things out. IOW, stack views are a way of getting sophisticated behavior 
without having to delve into constraints.

If this was macOS, I’d suggest using NSGridView instead of NSStackViews, but 
this new layout functionality hasn’t reached iOS yet.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Auto Layout Question

2017-05-24 Thread Saagar Jha
Could you attach a screenshot? You got cut off in the middle, so it’s hard to 
fully understand how the sizes relate.

Saagar Jha

> On May 24, 2017, at 08:52, Dave  wrote:
> 
> iOS Project.
> 
> Hi,
> 
> I’m trying to do something with auto layout and I can’t seem to get it right.
> 
> I want to create a View that holds a Text Field and a View. Call these LabelA 
> and ViewA. I want the Text to appear above the view and i want the View to 
> have the same aspect ratio (which is 1:1). I then want the same again, 
> e.g.another Text Field and View, positioned in the same manner.
> 
> In XCode/IB 8.3.2, here’s what I do:
> 
> I create a Label Field, and Set the Text to “Side A", set a custom font of 
> size 10, call it SideALabel. I create a UIView (call it SideAView) and set 
> its size to 35,35 and set the Background Colour to Red. I add an Aspect Ratio 
> constraint of 1:1 to SideAView  I then position and resize SideALabel so it 
> has a height of 10 and the width is 35 (same as the UIView). I set then an 
> Alignment Constraint Leading and Trailing Edges between SideALabel and 
> SideAView. I now embed the SideALabel and SideAView in a StackView, call this 
> SideAStackView. It now resizes/repositions the Stack and I move it where I 
> want it. When I switch to different iPhone’s in XCode/IB it rescales 
> accordingly. 
> 
> I actually want two of these Text/Views Combinations, so I duplicate the 
> Stack View (call it SideBStackView) and position it to the right of 
> SideAStackView). I change the Text to “Side B” and the background color the 
> View to Blue.
> 
>  Side A Side B
> +—+  +—+
> ||   |   |  
> |   Red  |   |  Blue  |  
> ||   |   |  
> +—+  +—+
> 
> The problem is that the StackViews resize so they are of different sizes.
> 
> I then embedded  SideAStackView and SideBStackView in another StackView - 
> call it SideSelectionStackView, I then set this new StackView’s distribution 
> to “Fill Equally” (I’ve also tried “Fill Proportionally” ) and set the 
> spacing so there is a gap between SideAStackView and SidebStackView. This 
> almost works, except the height of the Text and View Sizes are slightly 
> different. SideA has a higher text box/bigger font and the View is slightly 
> smaller. SideB Text is 
> 
> I’ve set the Left, Bottom, Right Constraints, so that basically it grows 
> upwards from the bottom of the Screen, but because of the aspect ratio it 
> can’t get too big. I have another View situated to the right of this and the 
> stack view is set to only extend so far from the left of this view.
> 
> I’ve tried everything I can think of to make this work but I’ve now run out 
> of ideas.
> 
> Am I missing something? Maybe I am going about this in the wrong way? 
> 
> Any help and suggestions on the best way of doing this would be greatly 
> appreciated.
> 
> I’m trying to prepare a demo for tomorrow afternoon and it would be really 
> great if I could show this displaying correctly.
> 
> All the Best
> Dave
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/saagar%40saagarjha.com
> 
> This email sent to saa...@saagarjha.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Auto Layout Question

2017-05-24 Thread Dave
iOS Project.

Hi,

I’m trying to do something with auto layout and I can’t seem to get it right.

I want to create a View that holds a Text Field and a View. Call these LabelA 
and ViewA. I want the Text to appear above the view and i want the View to have 
the same aspect ratio (which is 1:1). I then want the same again, e.g.another 
Text Field and View, positioned in the same manner.

In XCode/IB 8.3.2, here’s what I do:

I create a Label Field, and Set the Text to “Side A", set a custom font of size 
10, call it SideALabel. I create a UIView (call it SideAView) and set its size 
to 35,35 and set the Background Colour to Red. I add an Aspect Ratio constraint 
of 1:1 to SideAView  I then position and resize SideALabel so it has a height 
of 10 and the width is 35 (same as the UIView). I set then an Alignment 
Constraint Leading and Trailing Edges between SideALabel and SideAView. I now 
embed the SideALabel and SideAView in a StackView, call this SideAStackView. It 
now resizes/repositions the Stack and I move it where I want it. When I switch 
to different iPhone’s in XCode/IB it rescales accordingly. 

I actually want two of these Text/Views Combinations, so I duplicate the Stack 
View (call it SideBStackView) and position it to the right of SideAStackView). 
I change the Text to “Side B” and the background color the View to Blue.

  Side A Side B
+—+  +—+
||   |   |  
|   Red  |   |  Blue  |  
||   |   |  
+—+  +—+

The problem is that the StackViews resize so they are of different sizes.

I then embedded  SideAStackView and SideBStackView in another StackView - call 
it SideSelectionStackView, I then set this new StackView’s distribution to 
“Fill Equally” (I’ve also tried “Fill Proportionally” ) and set the spacing so 
there is a gap between SideAStackView and SidebStackView. This almost works, 
except the height of the Text and View Sizes are slightly different. SideA has 
a higher text box/bigger font and the View is slightly smaller. SideB Text is 

I’ve set the Left, Bottom, Right Constraints, so that basically it grows 
upwards from the bottom of the Screen, but because of the aspect ratio it can’t 
get too big. I have another View situated to the right of this and the stack 
view is set to only extend so far from the left of this view.

I’ve tried everything I can think of to make this work but I’ve now run out of 
ideas.

Am I missing something? Maybe I am going about this in the wrong way? 

Any help and suggestions on the best way of doing this would be greatly 
appreciated.

I’m trying to prepare a demo for tomorrow afternoon and it would be really 
great if I could show this displaying correctly.

All the Best
Dave











___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com