Last active
January 18, 2018 02:35
-
-
Save ryokosuge/15b7e201e22261a3c909 to your computer and use it in GitHub Desktop.
【Swift】UIImageの色を変える(塗りつぶす) ref: https://qiita.com/ryokosuge/items/d5389866f4403771ae76
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
extension UIImage { | |
func tint(color: UIColor) -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
color.setFill() | |
let drawRect = CGRectMake(0, 0, size.width, size.height) | |
UIRectFill(drawRect) | |
drawInRect(drawRect, blendMode: kCGBlendModeDestinationIn, alpha: 1) | |
let tintedImage = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return tintedImage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment