iOS - 去除UIImage的色调

3

我知道如何给UIImage着色:

UIImage* originalImage = curiv.image;
UIImage* imageForRendering = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
curiv.image = imageForRendering;
curiv.tintColor = [UIColor RedColor];

但是如何将带色调的UIImage还原为原始图像呢?

你可以在将 UIImage 着色为红色之前保存其 tintcolor,现在如果你想要取消着色,则设置之前保存的 tintcolor。如果不是这种情况,请提供更多代码以获取详细信息。 - Viral Savaj
@ViralSavaj 如何保存 UIImagetintColor?这是我关于 tintColor 的代码。 - sooon
请看一下我的答案。 - Viral Savaj
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Alladinian
1个回答

2

你可以试试这样的方法

UIImage* originalImage = curiv.image;
UIImage* imageForRendering = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
curiv.image = imageForRendering;
UIColor *prevTintColor = curiv.tintColor;
//set new Tint color as Red
curiv.tintColor = [UIColor redColor];


//Now if you want to set back previous color
curiv.tintColor=prevTintColor;

享受编码吧!!


它能够工作,但并没有真正解决我的问题。因为UIImages都是动态的,我可能有几个需要去色。不管怎样,感谢提供的解决方案。 - sooon
在WKInterfaceImage或UIImage对象中没有tintColor属性。开发者文档在developer.apple.com上没有公开任何名为“tintColor”的方法,但如果我错了,请随时纠正我。 - Ninja
@simonzhu,你说的有一半是对的,'UIImage'确实没有'tintColor'属性,但是我们可以在UIImageView中获取和设置tintColor。在上面的问答中,'curiv'是一个UIImageView对象,所以我们可以为它设置'tintColor'。你可以在苹果开发者文档中查看相关内容。 - Viral Savaj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接