Last active
October 21, 2017 06:18
-
-
Save 5oya/7b394f09093ef2fde3b37a036ed2c905 to your computer and use it in GitHub Desktop.
【iOS】図形(CGContext)にInnerShadowを加える
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 CGContext { | |
func setInnerShadow(withPath path: CGPath, shadowColor: CGColor, offset: CGSize, blurRadius: CGFloat) { | |
saveGState() | |
addPath(path) | |
clip() | |
setAlpha(shadowColor.alpha) | |
beginTransparencyLayer(auxiliaryInfo: nil) | |
guard let opaqueShadowColor = shadowColor.copy(alpha: 1.0) else { return } | |
setShadow(offset: offset, blur: blurRadius, color: opaqueShadowColor) | |
setBlendMode(.sourceOut) | |
setFillColor(opaqueShadowColor) | |
addPath(path) | |
fillPath() | |
endTransparencyLayer() | |
restoreGState() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment