gpt4 book ai didi

ios - UIView autoresizingMask 用于固定左右边距和灵活宽度

转载 作者:可可西里 更新时间:2023-11-01 03:05:17 29 4
gpt4 key购买 nike

我不知道如何在固定左右边距的情况下调整宽度。 Autoresize xCode

我没有找到任何固定的 led/右边距 API。

最佳答案

在代码中,要使 View 具有固定的左右边距以及灵活的宽度,您可以执行以下操作:

UIView *parentView = self.view; // adjust as needed
CGRect bounds = parentView.bounds; // get bounds of parent view
CGRect subviewFrame = CGRectInset(bounds, 20, 0); // left and right margin of 20
UIView *subview = [[UIView alloc] initWithFrame:subviewFrame];
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[parentView addSubview:subview];

根据需要进行调整以创建您的实际 subview 。调整 subviewFrame 以匹配您想要的边距。

如前所述,这将为您的 subview 提供固定的左右边距,每个 20 点和一个灵活的宽度。设置 autoresizingMask 时,任何未设置为灵活的组件都会自动修复(几乎)。这意味着上边距和高度也是固定的(因为它们未设置)。由于上边距和高度是固定的,因此下边距是隐式灵活的。由于显而易见的原因,不能同时固定所有三个跨越或上升/下降的值。

关于ios - UIView autoresizingMask 用于固定左右边距和灵活宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16049009/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com