Arrange 3 UIButtons(of equal width) side-by-side(并排排列 3 个 UIButtons(等宽))
问题描述
如何并排排列 3 个 UIButton.我正在使用自动布局.我的要求是:
How to arrange 3 UIButtons side-by-side.I am using Auto-layout. My requirement is:
1.无论设备如何,它们的宽度都应该相同
1.they should be equal width regardless of device
2.垂直占据视图的起点到终点
2.occupy vertically from starting to end of the view
我尝试了不同的方法,但未能实现.是否可以通过界面生成器实现
i tried different ways, i failed to achieve that. Is it possible through interface builder
推荐答案
有两种方法可以做到这一点.
There are 2 ways to do this.
方式一:
使用按钮的等宽限制
选择所有 3 个按钮并添加
Select all 3 buttons and add
上、左、右、高和等宽
方式2:使用堆栈视图
第 1 步: 添加 3 个按钮.
第 2 步: 选择所有按钮,选择后,单击右下角自动布局工具栏中的 堆栈按钮的故事板画布.见下图.
Step 2: Select all that buttons, Once you selected, click on the Stack button in the Auto Layout toolbar at the bottom right of the storyboard canvas. see below in image.
您也可以嵌入 From Editor -> Embed in -> StackView
第 3 步:将 约束 添加到 StackView.如下所示.
Step 3: Add Constraints to StackView. like below.
第 4 步:选择 StackView,选择后转到 属性检查器.将 Distribution 更改为 Fill Equally:
Step 4: Select StackView, Once selected go to Attributes inspector. Change the Distribution to Fill Equally:
它完成了!
这篇关于并排排列 3 个 UIButtons(等宽)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:并排排列 3 个 UIButtons(等宽)


基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01