Search code examples
iosstoryboarduitabbar

Why does't the selectedImage of a tab bar show up properly?


I'm trying to specify an image for the selectedImage of a UITabBar tab. This image is contained in the Asset Catalogs folder. The image is called secondActive.

The image that shows up in the Simulator, however, does not represent the image. It's just a blue square. When the tintColor changes, the color of the square changes too.

I'm specifying the selectedImage of the tab in the User Defined Runtime Attributes and in the Attributes Inspector.

Why does't the selectedImage of a tab bar show up properly?


Solution

  • This happens because your images do not contain alpha transparency. By default, bar and tab bar items use images in template rendering mode. You can tell the system to load it in original form, but then changing tint will not work (image will have the pixel color given in the image itself). Best to reauthor your images to include transparency where needed.