iOS using default color on image rendered as template

℡╲_俬逩灬. 提交于 2019-12-24 14:11:37

问题


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.



来源:https://stackoverflow.com/questions/33778682/ios-using-default-color-on-image-rendered-as-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!