如何使用此设置以编程方式创建 UIView?

发布于 2025-01-04 23:08:36 字数 179 浏览 3 评论 0原文

我想以编程方式创建一个 UIView,与 IB 中的此设置完全相同(参见屏幕截图)。

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

IB 中的 UIView

I'd like to create a UIView programmatically with the exact equivalent of this setup in IB (see screenshot).

Whatever I have attempted myself would not behave the same when rotating and autoresizing the view, so I need a sample from an expert.

UIView in IB

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满栀 2025-01-11 23:08:36

斯威夫特 2.0:

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

斯威夫特 3.0:

view.autoresizingMask = [.flexibleHeight, .flexibleWidth]

Swift 2.0:

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

Swift 3.0:

view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
枫林﹌晚霞¤ 2025-01-11 23:08:36

例子:

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

Example:

UIView *customView = [[UIView alloc] initWithFrame:frame];
[customView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];
放低过去 2025-01-11 23:08:36
  View.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin,.FlexibleWidth,.FlexibleHeight,.FlexibleTopMargin]
  View.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin,.FlexibleWidth,.FlexibleHeight,.FlexibleTopMargin]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文