本文介绍了将色调颜色设置为快速图像3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码在uilabel的右侧显示图像,当前uilabel的颜色为黑色,但我想知道如何将图像的颜色更改为绿色

I have the following code which shows an image on the right side of a uilabel, currently the color of my uilabel is black but I would like to know how I change the color of my image to green

我的代码:

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

这篇关于将色调颜色设置为快速图像3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:30