I I have an UIButton in my objective-c application. My button was modified adding text and image like:
- (void)centerButtonAndImageWithSpacing:(CGFloat)spacing {
CGFloat insetAmount = spacing / 2.0;
self.imageEdgeInsets = UIEdgeInsetsMake(0, -insetAmount, 0, insetAmount);
self.titleEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, -insetAmount);
self.contentEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, insetAmount);
}
And then I add the image with this code:
[self.myButton setImage:[UIImage imageNamed:@"imageButton.png"] forState:UIControlStateNormal];
I want change the tintColor of the image, but when I try change this, my code isn't work:
[self.myButton setTintColor:[UIColor redColor]];
I'm trying use this code, but didn't work:
UIImage* img = [UIImage imageNamed:imageName];
icon.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
icon.tintColor = [UIColor redColor];
How could I change the color of the imageButton?
We can apply the desired color for the transparent icons with the following way.
1.Drag the image on
Assets.xcassets
and In asset attribute inspector change the Render as attribute toTemplate Image
.2.And set the required tint color like below way.
Hope it will help you.