• Frank Tyger

    Doing what you like is freedom. Liking what you do is happiness.

January 2016

Color-fill UIImage programmatically in iOS7/iOS8/iOS9

With iOS7/iOS8/iOS9 you can color-fill a black-transparent png file, using the imageWithRenderingMode: method and the tintColor property.|

The iOS7/iOS8/iOS9: creates and returns a new image object with a specified rendering mode.

The rendering mode to use, is the UIImageRenderingModeAlwaysTemplate that draw the image as a template image, ignoring its color information.

Finally, the tintColor is the fill UIColor.
So, You can color-fill your png.

UIImage *img = [UIImage imageNamed:@"smile.png"];
self.imgOriginal.image = img;
self.imgColorFill.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.imgColorFill.tintColor = [UIColor colorWithRed:0.98 green:0.47 blue:0 alpha:1];


Read more →