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
Getting Video Snapshot for Thumbnail
Reading Long Characteristic Values Using Corebluetooth
Iphone, Obtaining a List of Countries in an Nsarray
How to Know If Nsassert Is Disabled in Release Builds
How to Change the Size of Uiactivityindicator
Compare Two Version Strings in Swift
Xcode 4.2 Jumps to Main.M Every Time After Stopping Simulator
"Initialize" Class Method for Classes in Swift
How to Add Buttons to Navigation Controller Visible After Segueing
Get Search Bar in Navigation Bar in Swift
Add Segmented Control to Navigation Bar and Keep Title with Buttons
How to Capture Picture with Avcapturesession in Swift
Open Specific View When Opening App from Notification
The Identity Used to Sign the Executable Is No Longer Valid
iOS Autolayout to Center My View Between Two Views
How to Make Both Header and Footer in Collection View with Swift