Contents

centerItemGroups

Customizable item groups to display in the center section of the navigation bar.

Declaration

var centerItemGroups: [UIBarButtonItemGroup] { get set }

Mentioned in

Discussion

Use this property to specify center item groups, groups of controls that appear in the navigation bar to provide quick access to your app’s capabilities. Center items appear in the center of the navigation bar for the UINavigationItem.ItemStyle.browser and UINavigationItem.ItemStyle.editor styles, and in the overflow menu for the UINavigationItem.ItemStyle.navigator style.

Optionally, you can allow people to customize the layout of center item groups and preserve that customization across app launches. When you create center item groups, you can choose from three types of behaviors:

  • Create a fixed group to disallow moving or removing that group from the navigation bar.

  • Create a movable group to allow moving a group in the navigation bar, but not removing it.

  • Create an optional group to allow moving, removing, or adding back that group.

The following code enables center item layout customization by assigning a customizationIdentifier. Then, it shows two approaches to creating center item groups: creating a group from an array of items and creating a group from a single item.

// Specify a unique customization identifier to enable navigation bar layout customization.
navigationItem.customizationIdentifier = "MyCustomNavigationItem"

// Create a fixed group with multiple items.
let editingGroup = UIBarButtonItemGroup.fixedGroup(items: [
    UIBarButtonItem(title: "Undo", image: UIImage(systemName: "arrow.uturn.backward"), primaryAction: UIAction { _ in
        // Implement undo action.
    }),
    UIBarButtonItem(title: "Redo", image: UIImage(systemName: "arrow.uturn.forward"), primaryAction: UIAction { _ in
        // Implement redo action.
    })
])

// Create a movable group from a single item.
let croppingItem = UIBarButtonItem(title: "Crop", image: UIImage(systemName: "crop"), primaryAction: UIAction { _ in
    // Implement crop action.
})
let croppingGroup = croppingItem.creatingMovableGroup(customizationIdentifier: "Cropping")

navigationItem.centerItemGroups = [editingGroup, croppingGroup]

See Also

Specifying custom views