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!
}
}
网友评论