我目前在使用 AutoLayout 时遇到困难.我正在使用界面生成器,并尝试将两个等宽的按钮并排放置,如下图所示.
I am currently having difficulty with AutoLayout. I am using interface builder and am trying to position two buttons of equal width side by side as illustrated in the following image.
从下面的预览图像中,我的 titleImage 已得到适当的约束并且可以正确显示,但按钮却没有.我已经尝试将按钮 1 与 titleImage 的前缘对齐,将 button2 与 titleImage 的后缘对齐,但是此时两个按钮之间的宽度分布变得倾斜,如下所示.
From the following Preview image, my titleImage has been properly constrained and is displaying correctly however the buttons are not. I have experimented by aligning button 1 with the leading edge of titleImage, and button2 with the trailing edge of titleImage, however the width distribution between the two buttons becomes skewed at this point, as demonstrated below.
我的目标是了解缺少哪些约束,并应将其应用于两个按钮以保持相同的宽度,而不管设备如何.如果可能的话,我想通过界面生成器而不是附加代码来实现这一点.
My objective is to understand what constraints are missing and should be applied to the two buttons to maintain equal widths regardless of device. If possible I would like to achieve this through interface builder as opposed to additional code.
添加如下约束
这篇关于iOS自动布局:两个等宽的按钮,并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!