Contents

UINavigationItem

The items that a navigation bar displays when the associated view controller is visible.

Declaration

@MainActor class UINavigationItem

Overview

When building a navigation interface, each view controller that you push onto the navigation stack must have a UINavigationItem object that contains the buttons and views you want to display 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.

A navigation item always reflects information about its associated view controller. The navigation item must provide a title to display when the view controller is topmost on the navigation stack. The item can also 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 when space is available.

To convey additional information about the view that a navigation item represents, use the subtitle property. For example, in a view controller that displays a list of messages, you could use the subtitle to indicate the number of unread messages or the last time the app fetched messages. To apply text styles to a navigation item’s title or subtitle, use the attributedTitle, attributedSubtitle, and largeAttributedSubtitle properties.

The backBarButtonItem property of a navigation item reflects the Back button you want to display when the current view controller is just below the topmost view controller. The Back button doesn’t appear 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.

Topics

Initializing an item

Configuring the title

Configuring the subtitle

Configuring the Back button

Specifying the navigation style

Specifying custom views

Getting and setting properties

Overriding the navigation bar’s appearance settings

Integrating search into your interface

Supporting navigation bar customization

Working with the overflow menu

Customizing the title menu

Renaming documents

See Also

Container view controllers