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

Reply via email to