【发布时间】:2024-01-14 14:17:01
【问题描述】:
我正在从服务器接收图像,然后根据用户选择的颜色,图像颜色将被更改。
我尝试了以下方法:
_sketchImageView.image = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[_sketchImageView setTintColor:color];
我的目标与我的目标相反(UIImage 外部的白色用所选颜色着色)。
出了什么问题?
我需要在这个问题上做同样的事情,提供的解决方案不能解决我的问题。 How can I change image tintColor in iOS and WatchKit
【问题讨论】:
-
如果你想用一些颜色填充图像,你需要更高级的解决方案。像这样:github.com/mxcl/UIImageWithColor
-
我觉得你需要背景色的效果,试试
[_sketchImageView setBackgroundColor: color] -
我之前尝试过这个解决方案,它给出了相同的结果。 //UIImage *img = [UIImage resizableImageWithColor:color cornerRadius:10]; // UIImage *img = [UIImage imageWithColor:color size:CGSizeMake(20, 20)]; UIImage *img = [UIImage imageWithColor:color]; _sketchImageView.image=img;
-
@saif [_sketchImageView setBackgroundColor: [UIColor clearColor]]; _sketchImageView.image = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [_sketchImageView setTintColor:color];给了我同样的结果
标签: ios objective-c uiimage uicolor tintcolor