toddg toddg - 9 months ago 80
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?


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)