iOS的自动布局:如何动态地均匀空间项目? [英] iOS auto layout: how to dynamically evenly space items?

查看:98
本文介绍了iOS的自动布局:如何动态地均匀空间项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要均匀空间X的项目,并为项目的容器可以有动态的宽度,我希望第一个和最后一个项目坚持左,右边缘:

I need to evenly space X items, and the container for the items can have dynamic width, and I want the first and last items to stick to left and right edge:

|-0-[item1]-[...]-[itemX]-0-|

所以,无论多么广泛的容器中,项目始终均匀分布的,如何与布局约束实现这个?

so that no matter how wide the container is, the items are always evenly spaced, how to implement this with layout constraints?

编辑:
我在想,如果我可以设置ITEM1和ITEM2有同样的间距为ITEM2和item3的等等,那么这应该是很容易的,但我不认为我可以设置它没有一个固定的宽度?

edit: I was thinking that if I can set item1 and item2 to have same spacing as item2 and item3 and so on, then this should be easy, but I don't think I can set it without a constant width?

推荐答案

您不能设置空格宽度相同,但你可以使用隔离的意见。

You can't set spaces to have the same width but you can use "spacer" views.

把所有的意见之间一种无形的观点,你可以设置的格式是这样...

Put an invisible view between all your views and you can set the format like this...

@"|[view1][spacer1][view2(==view1)][spacer2(==spacer1)]...[spacerN(==spacer1)][viewN]|"

这将使所有的意见,让他们之间是平等的空间。

This will make all the views have equal spaces between them.

请一定要设置隔离意见阿尔法0或隐或背景色清晰。

Make sure to set the spacer views as alpha 0 or hidden or background color clear.

这篇关于iOS的自动布局:如何动态地均匀空间项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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