Skip to content

Instantly share code, notes, and snippets.

@wendyliga
Created November 4, 2019 10:21
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 wendyliga/7cd1a914392c22653c4bd37b10828860 to your computer and use it in GitHub Desktop.
Save wendyliga/7cd1a914392c22653c4bd37b10828860 to your computer and use it in GitHub Desktop.
Implement layer masking with bazier path
image.imageModificationBlock = { image in
// try to set rounded corner only to top left and bottom left
var modifiedImage: UIImage?
var rect = CGRect(origin: CGPoint.zero, size: image.size)
UIGraphicsBeginImageContextWithOptions(image.size, false, UIScreen.main.scale)
let maskPath = UIBezierPath(roundedRect: rect, byRoundingCorners: [UIRectCorner.topLeft, UIRectCorner.bottomLeft], cornerRadii: CGSize(width: 10, height: 10))
maskPath.addClip()
image.draw(in: rect)
modifiedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return modifiedImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment