gpt4 book ai didi

ios - 在安全区域下方显示一个白框

转载 作者:行者123 更新时间:2023-11-29 11:38:12 25 4
gpt4 key购买 nike

如何在 iPhone X 安全区域的底部边缘下方显示一个白框(这样主页指示器就位于所述白框上)?我更愿意以编程方式执行此操作,这样我就不会弄乱 Storyboard 。

最佳答案

试试这个(在 viewDidLoad 中):

UIView *testView = [UIView new];
testView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:testView];
testView.translatesAutoresizingMaskIntoConstraints = NO;
[testView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = YES;
[testView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
[testView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
[testView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor].active = YES;

编辑

如果您只想为 iOS 11+ 完成此操作(这是有道理的)但支持以前的版本,那么请执行以下操作(假设 Xcode 9+):

if (@available(iOS 11.0, *)) {
UIView *testView = [UIView new];
testView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:testView];
testView.translatesAutoresizingMaskIntoConstraints = NO;
[testView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = YES;
[testView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
[testView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
[testView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor].active = YES;
}

关于ios - 在安全区域下方显示一个白框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48039792/

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