Keep UIButtons centered using autolayout in storyboard

送分小仙女□ 提交于 2019-12-05 07:55:59

You can achieve that by adding a constraint for each button to align the leading/trailing to the center of the container view, plus some separation between them.

How to do it:

  • For the left side button, add a constraint between the button and superview to center it horizontally.

  • Edit the constraint and change the "Second Item" attribute to be button1.trailing, and set a constant of 10 (or whatever distance you want between the right border of the button and the center of the screen).

  • For the right side button, add a constraint between the button and superview to center it horizontally.

  • Edit the constraint and change the "Second Item" attribute to be button2.leading and set a constant of -10 (or whatever distance you want between the left border of the button and the center of the screen).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!