Skip to content

Instantly share code, notes, and snippets.

@adow
Created August 17, 2016 01:42
Show Gist options
  • Save adow/f0b70f0bd6537e81bc56e84abc75daa3 to your computer and use it in GitHub Desktop.
Save adow/f0b70f0bd6537e81bc56e84abc75daa3 to your computer and use it in GitHub Desktop.
TintedImage
/// 对图片进行着色
func wxlive_imageWithTineColor(tintColor:UIColor,
blendMode:CGBlendMode = .DestinationIn) -> UIImage{
UIGraphicsBeginImageContextWithOptions(self.size, false, 0.0)
tintColor.setFill()
let bounds = CGRectMake(0.0, 0.0, self.size.width, self.size.height)
UIRectFill(bounds)
self.drawInRect(bounds, blendMode: blendMode, alpha: 1.0)
if blendMode != .DestinationIn {
self.drawInRect(bounds, blendMode: .DestinationIn, alpha: 1.0)
}
let tintedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return tintedImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment