1. ryokosuge

    Posted

    ryokosuge
Changes in title
+【Swift】UIImageの色を変える(塗りつぶす)
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,19 @@
+
+こんなシンプルな内容
+
+```swift:UIImageExtension.swift
+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
+ }
+}
+```
+
+同じ画像の色違いを表示したい時には使える関数だと思います。