iOS7
automaticallyAdjustsScrollViewInsets
extendedLayoutIncludesOpaqueBars
edgesForExtendedLayout
UIKit

Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms

Introduction

With the release of iOS 7, Apple introduced a host of new features and APIs that aimed to provide developers with more control and flexibility over the layout and behavior of their applications. Among these are three properties: `automaticallyAdjustsScrollViewInsets`, `extendedLayoutIncludesOpaqueBars`, and `edgesForExtendedLayout`. These properties are essential for developers working on user interfaces in iOS applications, especially those utilizing `UINavigationBar` and `UITabBar`.

automaticallyAdjustsScrollViewInsets

Overview

The `automaticallyAdjustsScrollViewInsets` property is a Boolean value that, when set to `YES`, allows a view controller to adjust the scroll view's content insets automatically. This is particularly useful when working with `UITableView` or `UICollectionView`, as it helps ensure that scrollable content is not obscured by navigation bars, tab bars, or status bars.

Technical Explanation

  • Default Behavior: By default, `automaticallyAdjustsScrollViewInsets` is set to `YES`. This means that if a view controller has a scroll view, the system will automatically adjust the content insets to account for the top and bottom bars.
  • Customization: If you set it to `NO`, you must manually adjust the content insets to prevent the scroll view's content from being obscured by the layout bars.

Example

  • Default Behavior: By default, this property is set to `NO`, meaning that if the navigation bar is opaque, the view controller's view does not extend beneath it.
  • Usage: Setting this property to `YES` can be beneficial when you want the content to appear beneath bars, allowing for a more immersive user experience, such as with translucent designs.
  • Default Behavior: The default value is `UIRectEdgeAll`, meaning the view controller's view can freely extend in all directions.
  • Customization: Use this property to control specific edges that should be extended beneath bars. This is especially useful when dealing with complex layouts where only certain parts of the view should extend.
  • Legacy Approach: Manually adjusting insets using properties like `automaticallyAdjustsScrollViewInsets` and `edgesForExtendedLayout`.
  • Modern Approach: Utilizing `safeAreaInsets` and `contentInsetAdjustmentBehavior` for adaptive layout adjustments.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms