ios - 在swift 3中将色调颜色设置为图像

标签 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 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

关于ios - 在swift 3中将色调颜色设置为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47587180/

相关文章:

ios - iPhone 启动画面作为一个简短的 mp4 视频 swift ios

ios - iPhone:如何获取当前毫秒数?

swift - 变量在它自己的初始值中使用 Swift 3

ios - 快速谷歌登录

ios - Swift 3 TableView Segue 到多个其他 TableView

ios - 拉伸(stretch) UIStackView 中的最后一个元素

ios - 在 UITextField 中的每种类型之后替换字符?

iphone - 应用程序设计 : Handling Core Data w/Background Contexts ; Merging w/Notifications Filtered by MOC

iphone - 在 iOS 中使用 AlertView

iphone - Segue被执行了两次