我看到了许多解决方案并应用了自动布局约束,但我仍然没有得到想要的解决方案.
I see many solution and applied auto layout constrains but still i am not getting desired solution.
当前结果:
给所有按钮的约束:
查看层次结构:
假设您想要的是让 3 个按钮彼此相等并使用 Interface Builder 填充屏幕宽度(没有代码,即:不是以编程方式),这是一个解决方案:
Assuming that what do you want is letting the 3 buttons equal each others and filling the width of screen using the Interface Builder (with no code, i.e: not programmatically), this is a solution:
您不需要将它们添加到视图中.只需按照以下步骤操作:
you don't need to add them in views. just follow these steps:
让我们从这个开始:
请注意,按钮还没有任何约束,只需将它们添加到视图底部(或者您想要显示它们的任何位置,对于此解决方案,我将它们显示在底部屏幕).确保它们中的 3 个具有相同的大小.
note that the buttons don't have any constraints -yet-, just add them to the to the bottom of the view (or where ever you want to display them, for this solution, I will display them in bottom of the screen). Make sure that the 3 of them have the same size.
为橙色按钮添加约束:
Adding constraints to the orange button:
添加以下约束:前导、底部空间和等高.
为蓝色按钮添加约束:
Adding constraints to the blue button:
添加以下约束:尾随、底部空间和等高.
为青色按钮添加约束:
Adding constraints to the cyan button:
到目前为止一切顺利,我们几乎完成了!
So far so good, we are almost done!
现在,选择 3 个按钮并添加以下约束:等宽.
Now, select the 3 buttons and add the following constraint: equal widths.
您的按钮应如下所示:
现在,您所要做的就是选择两个水平间距约束中的每一个,并将它们的常量设置为 0(来自尺寸检查器):
Now, all you have to do is select each of the two horizontal spacing constraints and set their constants to 0 -from the size inspector-:
你去吧:
我希望这会有所帮助,干杯.
I hope this helped, Cheers Up.
这篇关于为按钮提供相等的宽度约束时,自动布局设置不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!