如何以编程方式创建具有此设置的UIView?

9

我想通过编程方式创建一个与IB中完全相等的UIView设置(请参见截图)。

无论我自己尝试了什么,当旋转和自动调整视图时都不会表现出相同的行为,因此我需要来自专家的示例。

在IB中的UIView

3个回答

13

Swift 2.0:

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

Swift 3.0:

view.autoresizingMask = [.flexibleHeight, .flexibleWidth]

1
Swift 2.2同样适用。 - PeiweiChen
1
添加了 Swift 3 版本。 - LinusGeffarth
谢谢,@LinusG. ;) - Thomás Pereira

9

例子:

UIView *customView = [[UIView alloc] initWithFrame:frame];
[customView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];

谢谢。虽然看起来只需要灵活的宽度和高度,就像这里解释的那样:http://bit.ly/w5MaUx - anna

0
  View.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin,.FlexibleWidth,.FlexibleHeight,.FlexibleTopMargin]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接