iOS的自动布局如何水平拉伸2按钮 [英] iOS Autolayout how to stretch 2 button horizontally
问题描述
我需要从水平拉伸所有按钮:
I need to stretch all buttons horizontally from:
[button1][button2]
到
[ button1 ][ button2 ]
取决于屏幕的宽度。
depend on width of screen.
所以我寄托Button1以SuperView已经左上边缘。然后,我固定按钮2到Button1的水平,并设置等于高度Button1的,也寄托按钮2到右侧边缘。
So I have pinned button1 to superview for top and left edges. Then I pinned button2 to button1 horizontally and set equal height to button1 and also pinned button 2 to the right edges.
这是我的问题,现在:
推荐答案
您可以做这样的事情:
的左键的水平限制:
1.的左键的平等的领先的上海华的领导行为。
2.左键的尾随等于的centerX的上海华的(见下面的最后一个图像)。
Horizontal Constraints for the left button:
1. Leading of left button equals leading of superview.
2. Trailing of left button equals centerX of superview (See the last image below).
的右键的水平限制:
1.的右键的领导行为等于尾随的左键的。
2.尾随的右键的等于结尾的上海华的。
Horizontal Constraints for the right button:
1. Leading of right button equals trailing of left button.
2. Trailing of right button equals trailing of superview.
请注意:根据你想要什么把垂直限制
Note: Put the vertical constraints according to what you want.
下面是一个样本截图:
这篇关于iOS的自动布局如何水平拉伸2按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!