Skip to content

Instantly share code, notes, and snippets.

@5oya
Last active October 21, 2017 06:18
Show Gist options
  • Save 5oya/7b394f09093ef2fde3b37a036ed2c905 to your computer and use it in GitHub Desktop.
Save 5oya/7b394f09093ef2fde3b37a036ed2c905 to your computer and use it in GitHub Desktop.
【iOS】図形(CGContext)にInnerShadowを加える
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