Simulating selected tab bar effect

北城余情 提交于 2020-01-07 04:40:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!