ios 如何设置 UIViewController“扩展边缘”属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18875322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set UIViewController "extend edges" properties
提问by hgwhittle
I see the following selections in Storyboard for extending the edges of a UIViewController's view under navBars/tabBars:
我在 Storyboard 中看到以下选择,用于在 navBars/tabBars 下扩展 UIViewController 视图的边缘:
But how do I set these properties globally for all of my ViewControllers in code? As opposed to manually checking/unchecking on every ViewController in Storyboard.
但是如何在代码中为所有 ViewController 全局设置这些属性?与在 Storyboard 中的每个 ViewController 上手动检查/取消检查相反。
回答by dieworld
There is a couple of new properties in iOS7 to control those settings.
iOS7 中有几个新属性可以控制这些设置。
edgesForExtendedLayout
tells what edges should be extended (left, right, top, bottom, all, none or any combination of those). Extending bottom edge equals "Under Bottom Bars" tick, extending top edge equals "Under Top Bars" tick.
edgesForExtendedLayout
告诉应该扩展哪些边(左、右、上、下、所有、无或这些的任意组合)。延伸底部边缘等于“Under Bottom Bars”勾号,延伸顶部边缘等于“Under Top Bars”勾号。
extendedLayoutIncludesOpaqueBars
tells if edges should be automatically extended under the opaque bars. So if you combine those two settings you can mimic any combination of interface builder ticks in your code.
extendedLayoutIncludesOpaqueBars
告诉边缘是否应该在不透明条下自动延伸。因此,如果您结合这两个设置,您可以在代码中模拟界面构建器刻度的任意组合。
回答by Shaked Sayag
If you don't want to extend to any edges, just add:
如果您不想扩展到任何边缘,只需添加:
let viewController = UIViewController()
viewController.edgesForExtendedLayout = []
回答by jordiz
In Objective-C:
在 Objective-C 中:
- (void) viewDidLoad {
[super viewDidLoad];
[self initVars];
}
- (void) initVars {
self.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight | UIRectEdgeBottom;
self.extendedLayoutIncludesOpaqueBars = YES;
}
The properties that you want is:
你想要的属性是:
self.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeBottom;