北京旅游外贸网站建设,深圳有哪些做网站公司好,wordpress抖音,工程造价信息期刊2019独角兽企业重金招聘Python工程师标准 这是一个UIImage集合类#xff0c;可以很方便的对图片的染料#xff08;着色#xff09;#xff0c;增加亮度#xff08;闪电#xff09;和降低亮度#xff08;黑#xff09;和其他扩展的功能模块。 在swift下实… 2019独角兽企业重金招聘Python工程师标准 这是一个UIImage集合类可以很方便的对图片的染料着色增加亮度闪电和降低亮度黑和其他扩展的功能模块。 在swift下实现图片染色 import UIKitextension UIImage {/// Just change a colored color image, is to change the image TintColo////// - Parameter tintColor: Need to change the color of the color/// - Returns: Returns an imagefunc imageWithTintColor (tintColor: UIColor? nil, alpha: CGFloat) - UIImage? {let rect CGRect(x: 0.0, y: 0.0, width: self.size.width, height: self.size.height)UIGraphicsBeginImageContextWithOptions(rect.size,false,self.scale)draw(in: rect)let ctx UIGraphicsGetCurrentContext()ctx!.setFillColor((tintColor?.cgColor)!)ctx!.setAlpha(alpha);ctx?.setBlendMode(.sourceAtop)ctx!.fill(rect);let result UIGraphicsGetImageFromCurrentImageContext()UIGraphicsEndImageContext()return result}
} Usage To swift override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.let gift01ImageView UIImageView(image: UIImage(named: ic-gift))gift01ImageView.frame CGRect(x: 50.0, y: 50.0, width: 48.0, height: 48.0)self.view!.addSubview(gift01ImageView)let gift02ImageView UIImageView(image: UIImage(named: ic-gift)?.imageWithTintColor(tintColor: UIColor.blue, alpha: 0.5))gift02ImageView.frame CGRect(x: 125.0, y: 50.0, width: 48.0, height: 48.0)self.view!.addSubview(gift02ImageView)} gitHub Demo下载地址 转载于:https://my.oschina.net/kinglyphp/blog/786718