如何设置UIViewController“扩展边缘”属性

问题描述 投票:0回答:3

我在 Storyboard 中看到以下选择,用于在 navBars/tabBars 下扩展 UIViewController 视图的边缘:

enter image description here

但是如何在代码中为所有 ViewController 全局设置这些属性呢?与手动检查/取消检查 Storyboard 中的每个 ViewController 不同。

ios uiviewcontroller ios7
3个回答
81
投票

iOS7 中有几个新属性可以控制这些设置。

edgesForExtendedLayout
告诉应该延伸哪些边缘(左、右、上、下、全部、无或这些的任意组合)。延伸底部边缘等于“底部条形下方”勾选,延伸顶部边缘等于“顶部条形下方”勾选。

extendedLayoutIncludesOpaqueBars
指示边缘是否应自动延伸到不透明条下方。因此,如果您结合这两个设置,您可以在代码中模拟界面生成器标记的任意组合。


18
投票

如果你不想延伸到任何边缘,只需添加:

let viewController = UIViewController()
viewController.edgesForExtendedLayout = []

3
投票

在 Objective-C 中:

- (void) viewDidLoad {
   [super viewDidLoad];
   [self initVars];
}

- (void) initVars {
   self.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight | UIRectEdgeBottom;
   self.extendedLayoutIncludesOpaqueBars = YES;
}

您想要的属性是:

self.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeBottom;
© www.soinside.com 2019 - 2024. All rights reserved.