我在 Assets 目录中有一组图片,每张图片都有自己的颜色。当设备处于离线状态时,我需要将此图标全部显示为灰色。
问题是:当我在 Assets 目录中的图像上设置模板模式时,我无法使用默认颜色集中的图像。
我想避免生成双图标。
想法?
最佳答案
如果图像是纯色的,没有背景,您可以对其进行着色。
UIImage *image = [UIImage imageNamed:@"name"];
if (online) {
imageView.image = image;
} else {
imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[imageView setTintColor:[UIColor grayColor]];
}
我在应用程序中使用它在图像有新内容时对图像进行着色。
关于iOS 在呈现为模板的图像上使用默认颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33778682/