本文介绍了iOS 在渲染为模板的图像上使用默认颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我在资产目录中有一组图像,每个图像都有自己的颜色.当设备离线时,我需要将此图标全部显示为灰色.
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.
我想避免生成双图标.
想法?
推荐答案
如果图像是纯色的,没有背景,你可以给它着色.
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.
这篇关于iOS 在渲染为模板的图像上使用默认颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论