Reputation: 437
What kind of constraints should I put so that these four buttons are always in the center without effecting their shapes or sizes. Right now I can't seem to find a way to place them in the center as shown in the picture below.
Upvotes: 0
Views: 595
Reputation: 702
You can simply--
1.Take a UIView and give it constraints for horizontally and vertically centered and fixed height and width also.
Add 4 UIButtons in it with fixed width and height as shown in question.
Now add top leading trailing and bottom constraints to all UIButtons.
now your all buttons would be fit as you want......
Upvotes: 0
Reputation: 745
I hope this diagram helps. Don't forget to give width and height constraints to your button as well.
(sorry for bad handwriting)
Upvotes: 1
Reputation: 6213
You can group all this 4 view in UIStackView element, And defined the Spacing property between them, set Distribution property to Fill Equally. After that set constraint of Stack view according to you view.
Hope you find you solution.
Upvotes: 0
Reputation: 4104
One of the options is to create a UIView
that is always centered to its superview and has constant dimensions. Inside that view you can put the four buttons with constant sizes and appropriate constraints.
In that way all the button will always be centered.
Upvotes: 1
Reputation: 1259
You can use UIStackView for this. Place the buttons inside stackView, set constraints in reference to the stackView. Then set constraints on stackView to place it in the middle.
Upvotes: 0