Created
August 17, 2016 01:42
-
-
Save adow/f0b70f0bd6537e81bc56e84abc75daa3 to your computer and use it in GitHub Desktop.
TintedImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 对图片进行着色 | |
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