I want not to change the backgroundColor of an UIImage,
but rather to change the color of the whole image.
Because I have got standard forms which I can move from popover to the view.
In my App it is possible to tinker the images to one big image, i.e a table.
Moreover I want change the color to white brown or what else.
But the problem is: I can only change the backgroundColor
Is there any way to change the color of the UIImage?
Thank you in advance
setBlendMode(. multiply) ctx. draw(image. cgImage!, in: imageRect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage! } }
Add a button on your storyboard, select it Go to it's attribute inspector and select 'Background' property to choose the color.
The absolute simplest way to change colors of images (or icons in this case) is to use the SF Symbols where applicaple. This is a set of symbols Apple provides that can easily be used in your own app. You can download an app to help you find the correct symbol for you needs here.
The accepted answer is correct, but there is a much more easy way for UIImageView
:
Obj-C:
UIImage *image = [UIImage imageNamed:@"foo.png"]; theImageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [theImageView setTintColor:[UIColor redColor]];
Swift 2:
let theImageView = UIImageView(image: UIImage(named:"foo")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)) theImageView.tintColor = UIColor.redColor()
Swift 3:
let theImageView = UIImageView(image: UIImage(named:"foo")!.withRenderingMode(.alwaysTemplate)) theImageView.tintColor = UIColor.red
UIImage *image = [UIImage imageNamed:@"triangle.png"]; CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClipToMask(context, rect, image.CGImage); CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]); CGContextFillRect(context, rect); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored]; yourUIImageView.image = flippedImage;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With