【问题标题】:Need to Change value with UIColor for UIImage需要使用 UIColor 更改 UIImage 的值
【发布时间】:2019-08-01 19:15:33
【问题描述】:

我在这个应用程序的 github 上克隆了培根测试应用程序,他们在数组中添加了 3 个 UIColors 值,所以我需要更改 UIColor 提示为 UI Image 类型任何一个请帮助我enter image description here

【问题讨论】:

  • 你的问题是什么?

标签: swift swift3


【解决方案1】:

你可以使用这个扩展:

   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)

参考链接:How can I color a UIImage in Swift?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 2013-03-30
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多