Evgeniy Kleban Evgeniy Kleban - 2 months ago 28
Objective-C Question

Image with rendering mode not working

I want to change tint color of my image. I wonder why following code not working:

self.itemImage = [UIImageView new];
self.itemImage.contentMode = UIViewContentModeScaleAspectFit;
[_backgroundForCell addSubview:self.itemImage];


...

_itemImage.image = [UIImage imageNamed:vm.imgName];


...

self.imageView.image = [self.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.imageView setTintColor:[UIColor redColor]];


I still see this:

enter image description here

Answer

You may forgot to rename your variables:

replace

self.imageView.image = [self.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        [self.imageView setTintColor:[UIColor redColor]];

with

self.itemImage.image = [self.itemImage.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        [self.itemImage setTintColor:[UIColor redColor]];