Center Buttons with UIStackview
suggest changeStep 1 :- take 4 button in your Storyboard. Button1 , Button2 , Button 3 , Button4
Step 2 :- Give Fixed Height and width to All buttons .
![](/essential/ios/img/0038065480e65ecc0945aaacbcf4c9d65b70611a.gif)
Step 3 :- All 2 - 2 button’s pair in 2 stackview.
![](/essential/ios/img/b255e5ea34628ed6364502dea10213a5d8042714.gif)
Step 4 :- Set UIStackview Property for both .
Distribution -> Fill Equally
Spacing -> 5 (as per your requirement)
![](/essential/ios/img/43084b37076760259075dd12b4914ff443b92fca.png)
![](/essential/ios/img/deabc00ef2f50136d6bde1151a73fb4d6ddb1797.gif)
Step 5 :- Add both Stackview in one Stackview
![](/essential/ios/img/c21cca38c689efc9239b4f00bde8856a39e187bf.gif)
Step 6 :- Set Distribution = Fill equally Spacing =5
in main stackview (set According to your requirement)
![](/essential/ios/img/1de64b73134612e20b4d922f3b13008c4d60e028.gif)
Step 7 :- Now set Constrain to main stackview
center Horizontally in container
center vertically in container
and select Update Frame.
![](/essential/ios/img/4771b54c9af451585c313428fb017b38b674e078.gif)
Step 8 :- It’s time for Output for All device .
![](/essential/ios/img/fa644db62c01d0b5c9313b84740391348dee5da0.png)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents