【发布时间】:2019-08-01 19:15:33
【问题描述】:
我在这个应用程序的 github 上克隆了培根测试应用程序,他们在数组中添加了 3 个 UIColors 值,所以我需要更改 UIColor 提示为 UI Image 类型任何一个请帮助我enter image description here
【问题讨论】:
-
你的问题是什么?
我在这个应用程序的 github 上克隆了培根测试应用程序,他们在数组中添加了 3 个 UIColors 值,所以我需要更改 UIColor 提示为 UI Image 类型任何一个请帮助我enter image description here
【问题讨论】:
你可以使用这个扩展:
extension UIImageView {
func setImageColor(color: UIColor) {
let templateImage = self.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
self.image = templateImage
self.tintColor = color
}
}
let imageView = UIImageView(image: UIImage(named: "your_image_name"))
imageView.setImageColor(color: UIColor.purple)
【讨论】: