Search code examples
iosobjective-cuiimageview

Image with rendering mode as alwaysTemplate 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


Solution

  • 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]];