2

I found another stackoverflow post asking about essentially the exact same thing I am trying to solve (iOS Autolayout how to stretch 2 button horizontally), however I am still having issues figuring out how to go about aligning the edge of my object to the center of the superview. I need my two buttons to be aligned side-by-side just as in the example in the post I linked, but I cannot figure out how to reference the center of the superview to set my alignment to it, like is shown in the screenshots. Could someone provide a little more insight as to how to achieve the result mentioned in the linked post? Thank you so much.

Community
  • 1
  • 1
Randy Banks
  • 371
  • 1
  • 7
  • 25
  • One way is to set the pin the left button to the left edge. Right button to the right edge, Pin the left side of the right button to the right side oif the left button. Then set their widths equal. This is the easiest way for me if I'm using storyboard. – NSGangster Jan 29 '16 at 04:07
  • Make sure the constraint between the two buttons has a constant of 0 or however much space you want between them. – NSGangster Jan 29 '16 at 04:09
  • You know, I thought I had tried exactly this, and had a reply all typed on about how it didn't work for me. I decided to try it again just in case, and it worked. I narrowly avoided making an ass out of myself, haha. Thanks a lot man, really appreciate it – Randy Banks Jan 29 '16 at 04:14
  • Are you using storyboard? Or all programmatically? – NSGangster Jan 29 '16 at 04:16
  • I'm using the storyboard – Randy Banks Jan 29 '16 at 04:21
  • I've added an answer now that will hopefully help you out a little more with constraints on storyboard. – NSGangster Jan 29 '16 at 04:23

1 Answers1

0

One way is to set the pin the left button to the left edge. Right button to the right edge, Pin the left side of the right button to the right side of the left button. Then set their widths equal. This is the easiest way for me if I'm using storyboard.
Make sure the constraint between the two buttons has a constant of 0 or however much space you want between them.

enter image description here

If you take a look at this screenshot it will click that button when its red or yellow it will tell you what constraints you are missing on a button. If a view is misplaced simply hit the view and press cmd+option+"=" and it will give you a preview based on the constraints you've placed on it.

NSGangster
  • 2,397
  • 12
  • 22
  • Also, If you followed the blue guidlines on storyboard you can click the tiefighter on the bottom right corner and select the view you wish to layout and hit "add missing constraints" Double check the constraints after though to ensure they are what you want. – NSGangster Jan 29 '16 at 04:24