【问题标题】:How to fill image with color?如何用颜色填充图像?
【发布时间】:2019-12-11 00:39:09
【问题描述】:

我有一个 png 图像,我想用颜色填充。

我知道色调颜色,但它只给边框上色,我需要在边框内上色,就像这个想要的结果

我在这里展示了我想要实现的目标

【问题讨论】:

标签: ios swift uiimageview uiimage


【解决方案1】:

试试下面的代码,

extension UIImageView {
  func setImageColor(color: UIColor) {
    let templateImage = self.image?.withRenderingMode(.alwaysTemplate)
    self.image = templateImage
    self.tintColor = color
  }
}

你可以这样调用:

let imageView = UIImageView(image: UIImage(named: "your_image_name"))
imageView.setImageColor(color: UIColor.purple)

转自here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    • 2016-09-01
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 2023-02-20
    相关资源
    最近更新 更多