Contents

UITabBarItem

An object that describes an item in a tab bar.

Declaration

@MainActor class UITabBarItem

Overview

A tab bar item is a segment of a tab bar that represents a specific section of your app. A tab bar displays one or more items that allow the user to switch between the different sections. The user can select one item at a time.

The most common approach for displaying a tab bar is to use a tab bar controller. The controller’s tab bar displays an item for each view controller you provide when you set the viewControllers property or call the setViewControllers(_:animated:) method. You’re responsible for supplying the tab bar items. Do this by setting each view controller’s tabBarItem property. When the user selects an item, the tab bar controller displays its view controller. For more information, see UITabBarController.

You can also use a tab bar independent of a tab bar controller. After creating a tab bar, add it to your view hierarchy. Provide the items by setting the tab bar’s items property or by using the setItems(_:animated:) method. In this configuration, you’re responsible for updating the view hierarchy to display the correct content. Use UITabBarDelegate to know when the selection changes. For more information, see UITabBar.

The system provides several tab bar items for common use cases. If you need a custom item, create one with a title and an image. You can further customize the item by providing an alternate image that appears when the user selects it. By default, the item doesn’t display the images you provide. Instead, it generates new images from the alpha values of your images and tints them. To prevent this, provide images that use the UIImage.RenderingMode.alwaysOriginal rendering mode.

An item can adjust its appearance when in certain conditions. For example, you can specify different appearances for inline and compact inline layouts or for when the item’s state changes. To do this, set the item’s standardAppearance property. If you don’t want this behavior, you can set the individual properties on the item instead.

A tab bar item can display a supplementary value in a badge that provides extra information to the user. For example, the Phone app uses a badge’s value to display the number of missed calls. You can customize the badge’s appearance, including its background color and text attributes.

Topics

Creating a tab bar item

Configuring the item’s appearance

Configuring the item’s badge

See Also

Container view controllers