Class

UINavigationItem

A UINavigationItem object manages the buttons and views to be displayed in a UINavigationBar object. When building a navigation interface, each view controller pushed onto the navigation stack must have a UINavigationItem object that contains the buttons and views it wants displayed in the navigation bar. The managing UINavigationController object uses the navigation items of the topmost two view controllers to populate the navigation bar with content.

Overview

A navigation item always reflects information about the view controller with which it is associated. The navigation item must provide a title to display when the view controller is topmost on the navigation stack. In addition, the item may contain additional buttons to display on the right (or trailing) side of the navigation bar. You can specify buttons and views to display on the left (or leading) side of the toolbar using the leftBarButtonItems property but the navigation controller displays those buttons only if there is space available.

The backBarButtonItem property of a navigation item reflects the back button you want displayed when the current view controller is just below the topmost view controller. In other words, the back button is not used when the current view controller is topmost.

When specifying buttons for a navigation item, you must use UIBarButtonItem objects. If you want to display custom views in the navigation bar, you must wrap those views inside a UIBarButtonItem object before adding them to the navigation item.

For information about how navigation items work together with a navigation controller, custom view controllers, and the navigation bar to display their content, see View Controller Programming Guide for iOS.

Symbols

Initializing an Item

init(title: String)

Returns a navigation item initialized with the specified title.

Getting and Setting Properties

var title: String?

The navigation item’s title displayed in the center of the navigation bar.

var prompt: String?

A single line of text displayed at the top of the navigation bar.

var backBarButtonItem: UIBarButtonItem?

The bar button item to use when a back button is needed on the navigation bar.

var hidesBackButton: Bool

A Boolean value that determines whether the back button is hidden.

func setHidesBackButton(Bool, animated: Bool)

Sets whether the back button is hidden, optionally animating the transition.

var leftItemsSupplementBackButton: Bool

A Boolean value indicating whether the left items are displayed in addition to the back button.

Customizing Views

var titleView: UIView?

A custom view displayed in the center of the navigation bar when the receiver is the top item.

var leftBarButtonItems: [UIBarButtonItem]?

An array of custom bar button items to display on the left (or leading) side of the navigation bar when the receiver is the top navigation item.

var leftBarButtonItem: UIBarButtonItem?

A custom bar button item displayed on the left (or leading) edge of the navigation bar when the receiver is the top navigation item.

var rightBarButtonItems: [UIBarButtonItem]?

An array of custom bar button items to display on the right (or trailing) side of the navigation bar when the receiver is the top navigation item.

var rightBarButtonItem: UIBarButtonItem?

A custom bar button item displayed on the right (or trailing) edge of the navigation bar when the receiver is the top navigation item.

func setLeftBarButtonItems([UIBarButtonItem]?, animated: Bool)

Sets the left bar button items, optionally animating the transition to the new items.

func setLeftBarButton(UIBarButtonItem?, animated: Bool)

Sets the custom bar button item, optionally animating the transition to the new item.

func setRightBarButtonItems([UIBarButtonItem]?, animated: Bool)

Sets the right bar button items, optionally animating the transition to the new items.

func setRightBarButton(UIBarButtonItem?, animated: Bool)

Sets the custom bar button item, optionally animating the transition to the view.

Relationships

Inherits From