并排排列 3 个 UIButtons(等宽) [英] Arrange 3 UIButtons(of equal width) side-by-side

查看:44
本文介绍了并排排列 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(等宽)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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