Swift 需要使用UIImage的UIColor更改值

Swift 需要使用UIImage的UIColor更改值,swift,swift3,Swift,Swift3,我在github上克隆了bacon测试应用程序在此应用程序中,他们在数组中添加了3个UIColor,因此我需要更改UI图像类型的UIColor提示任何一个请帮助我您可以使用此扩展: extension UIImageView { func setImageColor(color: UIColor) { let templateImage = self.image?.withRenderingMode(UIImage.RenderingMode.alwaysTem

我在github上克隆了bacon测试应用程序在此应用程序中,他们在数组中添加了3个UIColor,因此我需要更改UI图像类型的UIColor提示任何一个请帮助我您可以使用此扩展:

   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)

参考链接:

你的问题是什么?