imageWithRenderingMode

Color-fill UIImage programmatically in iOS7

With iOS7 you can color-fill a black-transparent png file, using theimageWithRenderingMode: method and the tintColor property.

The imageWithRenderingMode: 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.

Color-fill UIImage programmatically with iOS7 | Daniele Galiotto | www.g8production.com

So, writing the code below or downloading the demo, 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];

Awesome!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s