Building the UIImageEffects class
Our final part to the image tinting on iOS is implementing the class that will return a tinted image from a template image and color. Create a new folder in the iOS project called Helpers
, add a new file called UIImageEffects.cs
, and implement the following:
public static class UIImageEffects { public static UIImage GetColoredImage(UIImage image, UIColor color) { UIImage coloredImage = null; UIGraphics.BeginImageContext(image.Size); using (CGContext context = UIGraphics.GetCurrentContext()) { context.TranslateCTM(0, image.Size.Height); context.ScaleCTM(1.0f, -1.0f); var rect = new CGRect(0, 0, image.Size.Width, image.Size.Height); // draw image, (to get transparancy mask) context.SetBlendMode(CGBlendMode.Normal); context.DrawImage(rect, image.CGImage); ...