Created
April 6, 2019 20:41
-
-
Save brandonasuncion/b5ea7fee2178a3b90fad8824f8f61a21 to your computer and use it in GitHub Desktop.
Example of creating "Squircles", as seen in Apple's iOS interface
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
| //: A UIKit based Playground for presenting user interface | |
| import UIKit | |
| import PlaygroundSupport | |
| class MyViewController : UIViewController { | |
| override func loadView() { | |
| let view = UIView() | |
| view.backgroundColor = .white | |
| self.view = view | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let cornerViewFrame = CGRect(x: 100, y: 100, width: 200, height: 200) | |
| let cornerRadius: CGFloat = 50 | |
| let regularCornerView = UIView(frame: cornerViewFrame) | |
| regularCornerView.layer.cornerRadius = cornerRadius | |
| regularCornerView.backgroundColor = .red | |
| view.addSubview(regularCornerView) | |
| let squircleView = UIView(frame: cornerViewFrame) | |
| squircleView.layer.cornerRadius = cornerRadius | |
| squircleView.backgroundColor = .yellow | |
| let squircleMask = CAShapeLayer() | |
| squircleMask.path = UIBezierPath(roundedRect: CGRect(origin: .zero, size: cornerViewFrame.size), cornerRadius: cornerRadius).cgPath | |
| squircleView.layer.mask = squircleMask | |
| view.addSubview(squircleView) | |
| } | |
| } | |
| // Present the view controller in the Live View window | |
| PlaygroundPage.current.liveView = MyViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment