iOS using default color on image rendered as templ

2019-08-11 03:59发布

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条回答
甜甜的少女心
2楼-- · 2019-08-11 04:32

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.

查看更多
登录 后发表回答