GBTC: Publish your app with easeDiscover GoodBarber Takes Care and simplify the app publication process for both the App Store and Google Play. Let us handle the technical details for you.Learn more about GBTC
GoodBarber allows you to create full customized, beautiful apps, in just a few clicks. Among the hundreds of other features, we implemented an icon coloration process, which you can use to create beautiful design effects.
We chose to let you choose amongst a large icon set — you can even upload your own TabBar icons — and you can imagine that it was completely impossible to anticipate all the customization possibilities. So we started to think about an automated customization process for these icons, and we wanted to keep a standard-based icon set (white PNGs with alpha channel only).
So here is what we developed to color the icons directly in the native client applications, with just a white PNG and a hexa color.
Color an image with CGImageCreateWithMask
The most pertinent function to color an image using a mask (our icon set) is CGImageCreateWithMask. This function takes a first parameter, the image to cut with the mask (the color), and a second parameter, the mask itself (the icon). Basically, the mask is a greyscale image, in which the white pixels are ignored and the black ones are kept, in alpha channel, according to their black intensity. So, we need to transform our original image to respect this specification.
We will follow two steps : create a negative image from our original image (white pixels need to become black), and add a white background. We choosed to create an UIImage category.
Create a negative image and replace the alpha with a white background
We could easily imagine how to adapt this piece of code to apply a texture, as an image, instead of a plain color.
To optimize the process, it's useful to cache the UIImage object generated (on the file system, or memory), instead of making a call of this function each time the image is displayed.