How to Set Uiviewcontroller "Extend Edges" Properties

How to set UIViewController extend edges properties

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.

What is the extend edge property in UIViewController for ?

By default, UITableViewController's views are automatically inset in iOS7 so that they don't start below the navigation bar/status bar. This is controller by the "Adjust scroll view insets" setting on the Attributes Inspector tab of the UITableViewController in Interface Builder, or by the setAutomaticallyAdjustsScrollViewInsets: method of UIViewController.

For a UIViewController's contents, if you don't want its view's contents to extend under the top/bottom bars, you can use the Extend Edges Under Top Bars/Under Bottom Bars settings in Interface Builder. This is accessible via the edgesForExtendedLayout property.

Reference: Why does UIViewController extend under UINavigationBar, while UITableViewController doesn't?

Why does UIViewController extend under UINavigationBar, while UITableViewController doesn't?

By default, UITableViewController's views are automatically inset in iOS7 so that they don't start below the navigation bar/status bar. This is controller by the "Adjust scroll view insets" setting on the Attributes Inspector tab of the UITableViewController in Interface Builder, or by the setAutomaticallyAdjustsScrollViewInsets: method of UIViewController.

For a UIViewController's contents, if you don't want its view's contents to extend under the top/bottom bars, you can use the Extend Edges Under Top Bars/Under Bottom Bars settings in Interface Builder. This is accessible via the edgesForExtendedLayout property.

UIViewController from XIB not resizing to UINavigationBar

I've managed with changing edgesForExtendedLayout property programatically in viewDidLoad:

self.edgesForExtendedLayout = UIRectEdgeRight | UIRectEdgeLeft | UIRectEdgeBottom;

With some help from question:
How to set UIViewController "extend edges" properties

Extend UIViewController's view without a navigation bar under status bar

After investigating tens of pages for hours, I've found an answer:

for (NSLayoutConstraint *constraint in self.view.constraints) {
if((constraint.firstItem == self.topLayoutGuide && constraint.secondItem == self.view) ||
(constraint.secondItem == self.topLayoutGuide && constraint.firstItem == self.view)) {
constraint.constant = -20;
}
}

For anyone wondering, I did not use a specific one answer, but a derived solution from this question: iOS7 - View under status bar - edgesForExtendedLayout not working.



Related Topics



Leave a reply



Submit