Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Starting in iOS7, the view controllers use full-screen layout by default. At the same time, you have more control over how it lays out its views, and that's done with those properties:</p> <p><strong>edgesForExtendedLayout</strong></p> <p>Basically, with this property you set which sides of your view can be extended to cover the whole screen. Imagine that you push a <code>UIViewController</code> into a <code>UINavigationController</code>. When the view of that view controller is laid out, it will start where the navigation bar ends, but this property will set which sides of the view (top, left, bottom, right) can be extended to fill the whole screen.</p> <p>Let see it with an example:</p> <pre><code>UIViewController *viewController = [[UIViewController alloc] init]; viewController.view.backgroundColor = [UIColor redColor]; UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; </code></pre> <p>Here you are not setting the value of <code>edgesForExtendedLayout</code>, therefore the default value is taken (<code>UIRectEdgeAll</code>), so the view extends its layout to fill the whole screen.</p> <p>This is the result:</p> <p><img src="https://i.stack.imgur.com/MOB6v.png" alt="without edges for extended layout, the view fills the whole screen"></p> <p>As you can see, the red background extends behind the navigation bar and the status bar.</p> <p>Now, you are going to set that value to <code>UIRectEdgeNone</code>, so you are telling the view controller to not extend the view to cover the screen:</p> <pre><code>UIViewController *viewController = [[UIViewController alloc] init]; viewController.view.backgroundColor = [UIColor redColor]; viewController.edgesForExtendedLayout = UIRectEdgeNone; UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; </code></pre> <p>And the result:</p> <p><img src="https://i.stack.imgur.com/ojAvO.png" alt="with edgesForExtendedLayout set, the view is just under the navigation"></p> <p><strong>automaticallyAdjustsScrollViewInsets</strong></p> <p>This property is used when your view is a <code>UIScrollView</code> or similar, like a <code>UITableView</code>. You want your table to start where the navigation bar ends, because you wont see the whole content if not, but at the same time you want your table to cover the whole screen when scrolling. In that case, setting <code>edgesForExtendedLayout</code> to None won't work because your table will start scrolling where the navigation bar ends and it wont go behind it.</p> <p>Here is where this property comes in handy, if you let the view controller automatically adjust the insets (setting this property to YES, also the default value) it will add insets to the top of the table, so the table will start where the navigation bar ends, but the scroll will cover the whole screen.</p> <p>This is when is set to NO:</p> <p><img src="https://i.stack.imgur.com/9Iapl.png" alt="the table will scroll over the whole screen, but starts out partially covered"></p> <p>And YES (by default):</p> <p><img src="https://i.stack.imgur.com/VVQHQ.png" alt="the table scrolls over the whole screen, and starts just under the navigation"></p> <p>In both cases, the table scrolls behind the navigation bar, but in the second case (YES), it will start from below the navigation bar.</p> <p><strong>extendedLayoutIncludesOpaqueBars</strong></p> <p>This value is just an addition to the previous ones. By default, this parameter is set to NO. If the status bar is opaque, the views won't be extended to include the status bar, even if you extend your view to cover it (<code>edgesForExtendedLayout</code> to <code>UIRectEdgeAll</code>).</p> <p>If you set the value to YES, this will allow the view to go underneath the status bar again.</p> <p>If something is not clear, write a comment and I'll answer it.</p> <p><strong>How does iOS know what UIScrollView to use?</strong></p> <p>iOS grabs the first subview in your ViewController's view, the one at index 0, and if it's a subclass of <code>UIScrollView</code> then applies the explained properties to it. </p> <p>Of course, this means that <code>UITableViewController</code> works by default (since the <code>UITableView</code> is the first view).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload