I am designing an interface in Swift, Xcode 7.2 which uses Stack views to 
surround an Image view; ( It’s a compass rose and the surrounding buttons are 
the Cardinal, InterCardinal and secondary-intercardinal directions)

It looks something like this.



[(Button1) (Button2) ……… (Button5)  ]   <---(Horizontal stack view)

Vertical Stack View below.
 
[(Button1)
.
.
.
.(Button3) ]



The bottom and right sides are mirror images of this, with the image view 
placed in a horizontal stack view, including the right vertical stack view.  
The UI itself looks good, with all the buttons remarkably well distributed 
around the image view.

The problem is this.

Because there are 5 buttons in the top and bottom rows, and 3 in the vertical 
left and right rows, the spacing in the vertical stack views are not as “tight” 
as I want it to be.

What I want is this. Lets call the space between the buttons “Empty Space"

[ Empty Space
Empty Space
Empty Space
Button1
Empty Space
Button2
Empty Space
Button3
Empty Space
Empty Space
Empty Space]

I tried the code below, and even though I think this on the right track , it 
has no effect, so I wonder if anyone has some insight into this.(It’s called in 
the vewController"s “ViewDidLoad” method.)
What I am trying to achieve, is to add a “spacer” (UILayoutGuide) between the 
upper( ?upper anchor) of the StackView and the first button, and in a mirrored 
fashion, between the lower button and the lower anchor of the stackView. And, 
hopefully, this will allow the Stackview’s “Equal Spacing" setting to produce 
what I want)


 func setupLayout(){
        let space1 = UILayoutGuide()
        let space2 = UILayoutGuide()
        
        self.leftStackView.addLayoutGuide(space1)
        self.leftStackView.addLayoutGuide(space2)
        
        
leftStackView.topAnchor.constraintEqualToAnchor(space1.topAnchor).active = true
        space1.bottomAnchor.constraintEqualToAnchor(button1.topAnchor).active = 
true
        space1.widthAnchor.constraintEqualToAnchor(space2.widthAnchor).active = 
true
        space2.topAnchor.constraintEqualToAnchor(button3.bottomAnchor).active = 
true
        
space2.bottomAnchor.constraintEqualToAnchor(leftStackView.bottomAnchor).active 
= true
        }

(buttonl1 and button2 are outlets, as is “leftStackView")

Thanks.







_______________________________________________

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