迅速-无法更改UIImage tintColor

问题描述

我有一个图案PNG图像,透明背景上有黑点,我需要以自定义颜色(例如黄色)更改点的颜色

我正在尝试在绘制颜色之前更改其颜色,但图像在透明状态下仍为黑色

let templateImage = UIImage(named: "spray7")!.withTintColor(.yellow,renderingMode: .alwaysTemplate)
                                        
 let image = templateImage.cgImage
 context.draw(image!,in: CGRect(x: 0,y: 0,width: 8,height: 8))

并且contextCGContext

任何建议都会有所帮助!

解决方法

正确的使用方法

let templateImage = UIImage(named: "spray7")!.tinted(with: .yellow)

代替

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...