How do I set accessory for tabview

Asked on 06/12/2025

1 search

To set an accessory for a UITabBarController in a UIKit app, you can follow these steps:

  1. Create a UITabAccessory: First, create a UITabAccessory with your content view. This accessory will be used to display additional content above the tab bar.

  2. Set the Bottom Accessory Property: Assign the created UITabAccessory to the bottomAccessory property of your UITabBarController. This will position the accessory view above the tab bar.

  3. Handle Space Constraints: When the accessory is in line with the tab bar, there might be less space available to display it. You can manage this by adjusting the content of your accessory view to accommodate the reduced space.

  4. Observe Changes: Register to observe changes to the Tab Accessory Environment Trait. This allows you to check if the accessory view is in line with the tab bar and update the view if needed.

  5. Automatic Trait Tracking: Utilize the new Update Properties method to update your accessory view with automatic trait tracking behavior.

For more detailed information, you can refer to the session Build a UIKit app with the new design (00:03:08) from WWDC 2025.