iOS using default color on image rendered as templ

2019-08-11 04:32发布

问题:

I've a set of images in the asset catalog, and every image has a own color. I need to show this icon all in gray when the device is offline.

The problem is: when I set template mode on image in asset catalog I can't be able to use the image in it's default color set.

I would like to avoid to generate double icons.

Ideas?

回答1:

If the image is solid without background, you can tint it.

    UIImage *image = [UIImage imageNamed:@"name"];
    if (online) {
       imageView.image = image;
    } else {
       imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        [imageView setTintColor:[UIColor grayColor]];
    }

I use it in an app to tint the image when it has new content.