Change tab bar item selected color in a storyboard
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Manipulating the appearance of tab bar items in an iOS application can significantly enhance the user interface and experience. One such customization is changing the tab bar item color when selected. By default, in iOS, tab bar items turn blue when selected. This article will delve into the steps involved in customizing the selected color of tab bar items directly through the storyboard, alongside additional technical tips.
Altering Tab Bar Item Selected Color in Storyboard
When working with storyboards in Xcode, altering the appearance of tab bar items can be done within the Interface Builder, which offers a visual approach. Here's a step-by-step guide:
Steps to Change the Tab Bar Item Selected Color
- Open Your Project: Launch Xcode and open your project.
- Access the Storyboard: Navigate to the storyboard where your UITabBarController is located.
- Select UITabBarController: Click on your Tab Bar Controller in the storyboard to display its properties in the Attributes Inspector.
- Customize Tab Bar Appearance: In the Attributes Inspector, locate the "Tab Bar" section:
- Look for the "Selected Image Tint" color option.
- Click on the color box beside "Selected Image Tint" to choose a new color from the color picker or input a custom color using RGB sliders, hex, or other options.
- Reflect Changes: After choosing your desired color, the new selected color will be applied to all tab bar items when selected.
By following these steps, you ensure that the selected color for tab bar items is visually coordinated with your application's overall theme.
Points to Consider
- Color Contrast: Ensure the selected color contrasts well with both the tab bar background and the unselected icons/text to maintain readability and accessibility.
- Dynamic Type Support: Consider users with different accessibility settings and ensure the color adaptation does not affect usability.
- Consistent Theme: Ensure that the color scheme is consistent across the application’s UI for a coherent appearance.
Technical Explanations
How UITabBarController Works with Colors
- Rendering Mode: Tab bar items utilize a rendering mode that determines how the images are displayed. By default, tab bar icons use the
UIImageRenderingModeAlwaysTemplate, allowing them to tint with the selected tint color. - Layer-Based Rendering: The appearance change in tab bar items involves layer-based rendering where the image and title layer's fill gets altered based on the selected tint.
- System vs. Custom Behaviors: While storyboards allow for easy customization, using code can offer additional dynamic behavior controls, such as overriding colors programmatically to respond to state changes.
Advanced Customization with Code
Beyond storyboards, changing the tab bar item colors can be accomplished programmatically within the AppDelegate or any suitable lifecycle method:

