Skip to content

Instantly share code, notes, and snippets.

@brandonasuncion
Created April 6, 2019 20:41
Show Gist options
  • Select an option

  • Save brandonasuncion/b5ea7fee2178a3b90fad8824f8f61a21 to your computer and use it in GitHub Desktop.

Select an option

Save brandonasuncion/b5ea7fee2178a3b90fad8824f8f61a21 to your computer and use it in GitHub Desktop.
Example of creating "Squircles", as seen in Apple's iOS interface
//: 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