tree: 65c4e1c8a7d7138a5e987422e74d4cf021389793 [path history] [tgz]
  1. docs/
  2. examples/
  3. src/
  4. tests/
  5. .jazzy.yaml
  6. README.md
components/NavigationBar/README.md

Navigation Bar

The Navigation Bar component is a view composed of a left and right Button Bar and either a title label or a custom title view.

Consistent with iOS design guidelines, the title in the navigation bar is centered by default. However, certain use cases may warrant use of a left aligned title such as: when there is a strong relationship between the title and additional content appearing in the navigation bar, or where centering the title causes ambiguity.

Design & API Documentation


Installation

Requirements

  • Xcode 7.0 or higher.
  • iOS SDK version 7.0 or higher.

Installation with CocoaPods

To add this component to your Xcode project using CocoaPods, add the following to your Podfile:

pod 'MaterialComponents/NavigationBar'

Then, run the following command:

pod install

Overview

Navigation Bar is a drop-in replacement for UINavigationBar with a few notable exceptions:

The MDCNavigationBar class is a composition of two Button Bars and a title label or title view. The left and right Button Bars are provided with the navigation item's corresponding bar button items.

Read the Button Bar section on UIBarButtonItem properties to learn more about supported UIBarButtonItem properties.


Usage

Importing

Before using Navigation Bar, you'll need to import it:

Swift

import MaterialComponents.MaterialNavigationBar

Objective-C

#import "MaterialNavigationBar.h"

Observing UINavigationItem instances

MDCNavigationBar can observe changes made to a navigation item property much like how a UINavigationBar does. This feature is the recommended way to populate the navigation bar's properties because it allows your view controllers to continue using navigationItem as expected, with a few exceptions outlined below.

If you intend to use UINavigationItem observation it is recommended that you do not directly set the navigation bar properties outlined in MDCUINavigationItemObservables. Instead, treat the observed navigationItem object as the single source of truth for your navigationBar's state.

Starting observation

To begin observing a UINavigationItem instance you must call observeNavigationItem:.

Swift

navigationBar.observe(navigationItem)

Objective-C

[navigationBar observeNavigationItem:self.navigationItem];

Stopping observation

Swift

navigationBar.unobserveNavigationItem()

Objective-C

[navigationBar unobserveNavigationItem];

Exceptions

All of the typical properties including UIViewController‘s title property will affect the Navigation Bar as you’d expect, with the following exceptions: