toddg toddg - 2 years ago 161
Swift Question

ImageWithRenderingMode AlwaysOriginal not working on UITabBar

Instead of using the tint color to indicate when a tab is selected, I just want to use the original images. These are the images I'm using:

Default: Default

Selected: Selected

I added the images in the Storyboard, and in my code to setup the TabBarController I have the following:

let manageItem = tabBar.items?[1]

But every time I build and run, I'm still getting the blue color when selected. Also, it seems to be altering the selected image. Here's what it looks like:

Not selected (second tab):

Unselected Screen shot


Selected screen shot

Why is it not using the original images?

Answer Source

As far as I recall imageWithRenderingMode returns new image, so you should rather use it like this :

let manageItem = tabBar.items?[1]
manageItem?.image = manageItem?.image?.imageWithRenderingMode(.AlwaysOriginal)
manageItem?.selectedImage = manageItem?.selectedImage?.imageWithRenderingMode(.AlwaysOriginal)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download