Skip to content

Instantly share code, notes, and snippets.

@ryokosuge
Last active January 18, 2018 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryokosuge/15b7e201e22261a3c909 to your computer and use it in GitHub Desktop.
Save ryokosuge/15b7e201e22261a3c909 to your computer and use it in GitHub Desktop.
【Swift】UIImageの色を変える(塗りつぶす) ref: https://qiita.com/ryokosuge/items/d5389866f4403771ae76
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