如何在iOS自动布局中为按钮添加等间距和等宽 [英] How to add Equal Spacing and equal width for button in iOS Auto layout

查看:30
本文介绍了如何在iOS自动布局中为按钮添加等间距和等宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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自动布局中为按钮添加等间距和等宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆