swift5自定义更改图标颜色,不使用原始颜色。

2020-05-28  本文已影响0人  Antlers777

let ima1 =UIImage(named:"wangzhi-2")

httpView.image= ima1?.imageWithTintColor(color:UIColor(red:101/255, green:125/255, blue:73/255, alpha:1))

extension UIImage{

    /// 更改图片颜色

    publicfuncimageWithTintColor(color :UIColor) ->UIImage{

        UIGraphicsBeginImageContext(self.size)

        color.setFill()

        letbounds =CGRect.init(x:0, y:0, width:self.size.width, height:self.size.height)

        UIRectFill(bounds)

        self.draw(in: bounds, blendMode:CGBlendMode.destinationIn, alpha:1.0)

        let tintedImage = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()

        returntintedImage!

    }

}

上一篇 下一篇

猜你喜欢

热点阅读