AutoLayout可以同等地分隔多个按钮吗? [英] Can AutoLayout equally space multiple buttons?

查看:115
本文介绍了AutoLayout可以同等地分隔多个按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个视图,其中包含一些垂直放置的按钮,我想在按钮之间的空间相等,当窗口调整大小。此视图上的约束(使用可视化格式)为:

I am trying to create a view that contains some buttons placed vertically and I would like the spaces between the buttons to be equal when the window is resized. The constraints (using the visual format) on this view are:

H:|-0-[button1]-0-|
H:|-0-[button2]-0-|
H:|-0-[button3]-0-|
H:|-0-[button4]-0-|
V:|-0-[button1]-(>=0)-[button2]-(>=0)-[button3]-(>=0)-[button4]-0-|

按钮显示正确,除了只有三个空格之一定义为> = 0

The buttons are displayed correctly except that only one of the three spaces defined to be >=0 is taken into account, while the other spaces remain zero (the layout is ambiguous).

有没有办法使用AutoLayout将这三个空格设置为相等?

Is there a way to set those three spaces to be equal using AutoLayout?

推荐答案

在每对按钮之间创建不可见的视图,然后将这些视图的宽度限制为相等。

Make invisible views that are between each pair of buttons, and then constrain the width of those views to be equal.

V:| - [button1] [spacerView1] [button2] [spacerView2] [button3] - |

V:|-[button1][spacerView1][button2][spacerView2][button3]-|

spacerView具有相同的宽度,并且第一间隔物视图的宽度应当≥0的约束。

Then create a constraint setting the spacerViews to have the same width, and a constraint that the width of the first spacer view should be >=0.

这篇关于AutoLayout可以同等地分隔多个按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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