以编程方式设置UIView的自动调整掩码? [英] Set UIView's autoresizing mask programmatically?

查看:138
本文介绍了以编程方式设置UIView的自动调整掩码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须以编程方式为 UIView 设置autoresizingMask。

I have to set autoresizingMask programmatically for UIView.

我不知道如何实现它。

I don't know how to implement this.

推荐答案

为了实现你在屏幕截图中所拥有的,你需要做与DrummerB建议相反的事情。你想要一个固定的上限,这样你就可以使每一方都灵活:

To achieve what you have in that screen shot you need to do the opposite of what DrummerB suggests. You want a fixed top margin so you make every other side flexible like so:

目标C:

view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
                        UIViewAutoresizingFlexibleLeftMargin |
                        UIViewAutoresizingFlexibleBottomMargin;

没有将一方设置为灵活意味着它将被修复(默认行为),这就是为什么有没有UIViewAutoResizingFixedTopMargin(因为它与未设置UIViewAutoresizingFlexibleTopMargin相同)

Not setting a side as flexible means that it will be fixed (default behaviour), thats why there is no such thing as UIViewAutoResizingFixedTopMargin (since its the same as not setting UIViewAutoresizingFlexibleTopMargin)

编辑Swift:

view.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin]

感谢Tom Calmon添加swift版本1st。

Credit to Tom Calmon for adding the swift version 1st.

干杯。

这篇关于以编程方式设置UIView的自动调整掩码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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