How to set UIViewController “extend edges” propert

2019-01-13 18:19发布

I see the following selections in Storyboard for extending the edges of a UIViewController's view under navBars/tabBars:

enter image description here

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.

3条回答
姐就是有狂的资本
2楼-- · 2019-01-13 18:40

If you don't want to extend to any edges, just add:

let viewController = UIViewController()
viewController.edgesForExtendedLayout = []
查看更多
不美不萌又怎样
3楼-- · 2019-01-13 18:51

In 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;
查看更多
成全新的幸福
4楼-- · 2019-01-13 18:52

There is a couple of new properties in iOS7 to control those settings.

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.

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.

查看更多
登录 后发表回答