Created
November 4, 2019 10:21
-
-
Save wendyliga/7cd1a914392c22653c4bd37b10828860 to your computer and use it in GitHub Desktop.
Implement layer masking with bazier path
This file contains hidden or 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
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