Ios 将“着色颜色”设置为swift 3中的图像

Ios 将“着色颜色”设置为swift 3中的图像,ios,iphone,swift3,uiimage,Ios,Iphone,Swift3,Uiimage,我有下面的代码,它在uilabel的右侧显示了一个图像,目前我的uilabel的颜色是黑色的,但我想知道如何将图像的颜色更改为绿色 我的代码: let image:UIImage=UIImage(named:"ic_premium")! let attachment = NSTextAttachment() attachment.image=image attachment.bounds = CGRect(x: 0, y: -3, width: 15, height: 15) let attri

我有下面的代码,它在uilabel的右侧显示了一个图像,目前我的uilabel的颜色是黑色的,但我想知道如何将图像的颜色更改为绿色

我的代码:

let image:UIImage=UIImage(named:"ic_premium")!
let attachment = NSTextAttachment()
attachment.image=image
attachment.bounds = CGRect(x: 0, y: -3, width: 15, height: 15)
let attributedString = NSMutableAttributedString(string: item_empresa[indexPath.item].nombre_emp!)
attributedString.append(NSAttributedString(attachment: attachment))
cell.lbl_nombreEmpresa.attributedText = attributedString
提前感谢

尝试以下代码

let image = UIImage(named:"ic_premium")!
let templateImage = image.withRenderingMode(.alwaysTemplate)
templateImage.tintColor = UIColor.green
attachment.image = templateImage

没有图标。不会改变我的朋友