目标C:如何以编程方式在安全区域内创建self.view

目标C:如何以编程方式在安全区域内创建self.view,第1张

目标C:如何以编程方式在安全区域内创建self.view

在Objective-C中尝试此 *** 作,请参见

UIView * myView = // initialize view using IBOutlet or programticallymyView.backgroundColor = [UIColor redColor];myView.translatesAutoresizingMaskIntoConstraints = NO;if (@available(iOS 11, *)) {    UILayoutGuide * guide = self.view.safeAreaLayoutGuide;    [myView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;    [myView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;    [myView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES;    [myView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES;} else {    UILayoutGuide *margins = self.view.layoutMarginsGuide;    [myView.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES;    [myView.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES;    [myView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].active = YES;    [myView.bottomAnchor constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor].active = YES;}// Refresh myView and/or main view[self.view layoutIfNeeded];//[self.myView layoutIfNeeded];


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5666567.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存