How can I change image tintColor

change button image tint color swift
swiftui image tint color
change image tint color objective-c
change color of button image
ios uibutton change image color
apply color to image swift
ios mask image with color
tintcolor ios

I'm receiving image from a server, then based on a color chosen by the user, the image color will be changed.

I tried the following :

_sketchImageView.image = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[_sketchImageView setTintColor:color];

i got the opposite of my goal (the white color outside UIImage is colored with the chosen color).

what is going wrong?

i need to do the same in this question,the provided solution doesn't solve my case. How can I change image tintColor in iOS and WatchKit

Try to generate new image for yourself

UIImage *newImage = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIGraphicsBeginImageContextWithOptions(image.size, NO, newImage.scale);
[yourTintColor set];
[newImage drawInRect:CGRectMake(0, 0, image.size.width, newImage.size.height)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

_sketchImageView.image = newImage;

And use it.

Good luck

======= UPDATE =======

This solution will only change color of all pixel's image.

Example: we have a book image: http://pngimg.com/upload/book_PNG2113.png

And after running above code (exp: TintColor is RED). We have:

SO: how your image is depends on how you designed it

alwaysTemplate) imageView.image = tintableImage }. The tint color of a UIImageView is the standard iOS 7 blue by default, but you can change  How can I change image tintColor in iOS and WatchKit. Practice As Follows. Try to generate new image for yourself. UIImage *newImage = [_sketchImageView.image

In Swift you can use this extension: [Based on @VietHung's objective-c solution]

extension UIImage {
    func imageWithColor(color: UIColor) -> UIImage? {
        var image = imageWithRenderingMode(.AlwaysTemplate)
        UIGraphicsBeginImageContextWithOptions(size, false, scale)
        color.set()
        image.drawInRect(CGRect(x: 0, y: 0, width: size.width, height: size.height))
        image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
}

The specific mode that we will use here is UIImage.RenderingMode.​alwaysTemplate which will draw the image as a template image, ignoring its color information. In WatchKit for Apple Watch apps, you can set the tint color for a template image. You must add your image to an Asset Catalog in your WatchKit App, and set the image set to be rendered as a Template Image in the Attributes Inspector. Unlike for an iPhone app, you cannot set the template rendering in code in the WatchKit Extension at present.

In swift 2.0 you can use this

let image = UIImage(named:"your image name")?.imageWithRenderingMode(.AlwaysTemplate)
let yourimageView.tintColor = UIColor.redColor()
yourimageView.image = image

In swift 3.0 you can use this

let image = UIImage(named:"your image name")?.withRenderingMode(.alwaysTemplate)
let yourimageView.tintColor = UIColor.red
yourimageView.image = image

Below is the code snippet, that will change color of UIImage or image in swift language. The code is self explanatory, first we will get the image as template image  Change Color Tint Free Online Photo Editor. Photo, sketch and paint effects. For Tumblr, Facebook, Chromebook or WebSites. Lunapics Image software free image, art & animated Gif creator.

Try something like this

UIImage *originalImage = _sketchImageView.image
UIImage *newImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,50,50)]; // your image size
imageView.tintColor = [UIColor redColor];  // or whatever color that has been selected
imageView.image = newImage;
_sketchImageView.image = imageView.image;

Hope this helps.

Upload your photo for tint. Use Lunapic to Tint your Image! Use form above to pick an image file or URL. In the future, access this tool from the menu above LunaPic > Filters > Color Tint. One thing you can do is, just add your images to Assets folder in XCode and then change the rendering mode to Template Image, so whenever you change the tint color of UIImageView, it will automatically makes change to image.

In Swift 3.0 you can use this extension: [Based on @VietHung's objective-c solution]

extension UIImage {
    func imageWithColor(_ color: UIColor) -> UIImage? {
        var image = imageWithRenderingMode(.alwaysTemplate)
        UIGraphicsBeginImageContextWithOptions(size, false, scale)
        color.set()
        image.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
        image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
}

How do I change the color of the tint on my Android phone? World's simplest online Portable Network Graphics color changer. Just import your PNG image in the editor on the left, select which colors to change, and you will instantly get a new PNG with the new colors on the right. Free, quick, and very powerful. Import a PNG – replace colors. Created with love by team Browserling.

How do I change the drawable tint color in android programmatically? Color Tint Free Online Photo Editor. Photo, sketch and paint effects. For Tumblr, Facebook, Chromebook or WebSites. Lunapics Image software free image, art & animated Gif creator.

Always changed tint colour of UIView, but this time needs to change colour of image in swift Duration: 6:01 Posted: Apr 23, 2018 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.

A new version of the image that incorporates the specified tint color. Discussion. For bitmap images, this method draws the background tint color followed by the  @Banana, this is a known issue of the images not using the tint color. I had reported it to Apple a while back and they marked it as a duplicate so they definitely know about it. The workaround is to not set your UIImageView to an image on the Storyboard.

Comments
  • If you want to fill image with some color you need more advanced solution. Like this: github.com/mxcl/UIImageWithColor
  • i think you need the effect of background color , try [_sketchImageView setBackgroundColor: color]
  • i tried this solution before and it gives the same result. //UIImage *img = [UIImage resizableImageWithColor:color cornerRadius:10]; // UIImage *img = [UIImage imageWithColor:color size:CGSizeMake(20, 20)]; UIImage *img = [UIImage imageWithColor:color]; _sketchImageView.image=img;
  • @saif [_sketchImageView setBackgroundColor: [UIColor clearColor]]; _sketchImageView.image = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [_sketchImageView setTintColor:color]; gives me the same result
  • thanx a lot, lets say that i have a book image, this solution colored the image outside the book borders.. i want the opposite,i.e the book itself to be colored. any idea why is this happening?
  • I think you need to re-design your book image. I've just edited my post. See it
  • Yeah.yessss.. i tried your image and it works fine :) i really appreciate
  • didn't work for me, I prefer this answer : stackoverflow.com/questions/19274789/…
  • For Swift 3.0, you'll want to use withRenderingMode, not imageWithRenderingMode.
  • thanx for the help, but this changes the image to white image (as it is a blank one )
  • So you are saying that your _sketchImageView.image is blank?
  • No,it is not..i mean after applying your code i got a white image