I'm writing a custom UITabBar replacement, and I would like to know how to recreate the filter that the built-in implementation does with the UITabBarItem image - that blue shining on selected tabs and gray gradient on unselected ones. I guess it's a matter of using the source image alpha value as a mask and overlay it with a pre-made blue (or whatever color) shining image and another one grayed out, but I would like to know what is the best approach from a code point of view.
Best,
Edit: Fixed up the blue filter a little
Edit2: Cleaned up the grey filter
I required code to do these effects, so I wrote a couple functions for them:
To make the blue filter effect work you'll need to include this image in your project as "selection_gradient.png": selection_gradient.png http://oi55.tinypic.com/bgwv0j.jpg
Also, you may want to play with the defines to get the effect exactly how you like, I didn't take much time to perfect them, though they look good enough to me.
Of course I don't know the exact filters that Apple applied, but I "guestimated" them and they look alright to me. I'm not sure if these functions are iPhone 4 compatible because I'm only using them in an iPad app, but it wouldn't be hard to edit them to your liking.
Try this one; it's shorter:
Edit: Use @poiuy_qwert's "selection_gradient.png"
If you're interested in an exact replica of the UITabBarItem filter, then try this solution. You don't need to include any extra images into your project.
I'm fully aware that this is a total hack and I make no promises as to compatibility in the future, but it works in both iOS 5 and iOS 6 as far as I can tell, and with proper error handling I think it can be useful. Here it goes:
Again, I'm aware that this is a shaky solution at best, but if you're interested in a perfect replica, here it is.