iOS 在呈现为模板的图像上使用默认颜色

标签 ios objective-c uiimageview uiimage

我在 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/

相关文章:

ios - 更新 TableViewCell 中的 UIButton State 会改变其他行

ios - SpriteKit 相机不以 aspectFit 为中心

ios - 在没有临时配置文件的情况下部署应用程序

objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?

ios - 围绕屏幕右侧旋转 UIView

ios - 如何删除隐藏的 UIImage 空间?

objective-c - 从 m4a 或 wav 解析标题?

ios - malloc : nano zone abandoned due to inability to preallocate reserved vm space

swift - 如何在使用 Kingfisher 从 URL 加载图像后调整 UIImageView 的大小

ios - 从 ViewController 到 UIImageView 的 photoImageView 导出无效。 socket 不能连接到重复的内容