Created
December 9, 2017 05:29
-
-
Save mpdroid/fd8dbeabf8dc874e78937db0273bf4bc to your computer and use it in GitHub Desktop.
Picture-frame using CAShapeLayer
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
| import UIKit | |
| import PlaygroundSupport | |
| let bounds = CGRect(x: 0, y: 0, width: 400, height: 200) | |
| let uiview = UIView(frame: bounds) | |
| uiview.backgroundColor = UIColor.clear | |
| PlaygroundPage.current.liveView = uiview | |
| let shape = CGRect(x: 100, y: 50, width: 200, height: 100) | |
| let maskLayer = CAShapeLayer() | |
| maskLayer.frame = bounds | |
| maskLayer.path = UIBezierPath(roundedRect: shape, cornerRadius: 16).cgPath | |
| maskLayer.backgroundColor = UIColor.clear.cgColor | |
| maskLayer.fillRule = kCAFillRuleEvenOdd | |
| let frameview = UIView(frame: bounds) | |
| frameview.backgroundColor = UIColor.red.withAlphaComponent(0.8) | |
| frameview.layer.mask = maskLayer | |
| let baseview = UIView(frame: bounds) | |
| baseview.backgroundColor = UIColor.blue.withAlphaComponent(0.8) | |
| uiview.addSubview(baseview) | |
| uiview.insertSubview(frameview, aboveSubview: baseview) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment