问题
Partly as a programming exercise, and partly because we may need to include such images in an app some day, I've been trying to figure out how to draw an image like the selected tab in a UITabBar
.
The basic operation is simple enough in concept: the icon's alpha is used as a mask to draw the blue gradient image onto the tab. (Though I can't for the life of me figure out how one actually uses an image's alpha as a mask in Core Graphics. I ended up drawing the gradient first, then using a transparency layer with kCGBlendModeDestinationIn
to draw the icon.)
But look closely at the real thing, and you'll see that there's also a bright outline just inside the opaque regions of the icon. How would one achieve that effect? I'm guessing that this is another drawing pass, maybe blending in lightening mode, but is there a straightforward way to get just the edge pixels of the icon?
回答1:
I wrote some code to do both the "gray filter" and the "blue filter" applied by UITabBarItem's as an answer to another question over here. I essentially did the same stuff you did and then applied the brightening of the edges by a manual loop through the pixels. Have fun!
来源:https://stackoverflow.com/questions/4052549/simulating-selected-tab-bar-effect