David
David

Reputation: 7456

Horizontal Center in Container bug in Storyboard of Xcode 6?

I was trying to put two buttons right next to each other, one taking up the left half of the screen, and the other taking up the right half of the screen. I found it perplexing that when I set Horizontal Center In Container for both of them that the left button had the property set correctly (center of button), but that the right button had the property set to the center of the View Controller!

I looked into this further and discovered that it takes this behavior whenever its on the right side:

Left side Moving to the right... On right side now... Property clearly not in center of button

In my pictures, I'm using a UIView with a black background, but it is applicable to anything. Is this the desired behavior? How else would I have two buttons laid out like I stated above?

Upvotes: 0

Views: 1058

Answers (2)

lojals
lojals

Reputation: 999

You can put your two buttons embebed in a UIView then put a Horizontal center Constraint in that UIView

Two buttons inside a UIView centered

Upvotes: 0

Senõr Ganso
Senõr Ganso

Reputation: 1734

Why do you use Horizontal Center In Container for your task? It should make both buttons appear in the centre of the container.

Do this instead:

  1. Choose both buttons and set "Equal width" constraint.
  2. For the left button, set leading constraint to the superview, and trailing to the right button.
  3. For the right button, set leading constraint to your left button, and trailing to superview.

Upvotes: 3

Related Questions