iOS 在渲染为模板的图像上使用默认颜色

编程入门 行业动态 更新时间:2024-10-28 16:17:16
本文介绍了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:关键词]

本文发布于:2023-04-29 04:05:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   颜色   模板   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!