我是 Xcode 中自动布局约束的新手.我有一个底部视图,例如 UITabBar
和 6 个 UIButtons
.在没有限制的情况下,我将这些按钮与每个按钮的 5 个空格填充对齐,每个按钮的宽度为 50.现在,我正在尝试通过使用自动布局来支持所有屏幕尺寸.
Am new to Auto layout constraints in Xcode. I have one Bottom View like UITabBar
with 6 UIButtons
. Without constraints I aligned those buttons with 5 space padding with each buttons and each buttons has 50 width.
Now,I am trying to make it by using Auto layout to support all Screen sizes.
在 Storyboard 约束中,我为 6 个按钮设置了相等的宽度,我做了 60 个每个按钮之间的空间.我将第一个按钮 0 设置为前导空格和我将最后一个按钮 0 设置为尾部约束.
In Storyboard constrains I set equal width for 6 buttons and I made 60 space between each buttons. I set first button 0 to leading space and I set the last button 0 to tail constraints.
我希望所有设备尺寸的视图之间的 按钮具有相同的宽度和灵活的空间
.
I want the buttons with equal width and flexible spaces
between views in all device sizes.
谁能帮帮我?寻求帮助.提前致谢.
Can anyone pleas help me? Looking for the help. Thanks in advance.
检查这张图片并做出如下约束...
check this image and made your constraints like below...
结果:-不同尺寸的预览
使用 Stackview(适用于 iOS 9.0 及更高版本)
With Stackview (For iOS 9.0 and above)
注意:如果您必须为 iOS 9 及更高版本制作应用程序,那么 UIStackView
是您的另一个选择
NOTE: If you have to make app for iOS 9 and later then
UIStackView
is another option for you
这篇关于如何在 iOS 自动布局中为按钮添加等间距和等宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!