【问题标题】:set Tint color to image in swift 3 [duplicate]在swift 3中将色调颜色设置为图像[重复]
【发布时间】:2018-05-15 04:37:06
【问题描述】:

我有以下代码,它在 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

提前致谢

【问题讨论】:

    标签: ios iphone swift3 uiimage


    【解决方案1】:

    试试下面的代码

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

    【讨论】:

    • 没有图标。不会改变我的朋友
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2018-07-22
    • 2013-04-22
    • 2017-02-04
    • 1970-01-01
    • 2021-06-16
    • 2022-11-30
    相关资源
    最近更新 更多