Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created June 16, 2020 13:18
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 alexnikol/fd0bd1c182022b68a124a9c65e6fa212 to your computer and use it in GitHub Desktop.
Save alexnikol/fd0bd1c182022b68a124a9c65e6fa212 to your computer and use it in GitHub Desktop.
UIBezierPath-ReadyToUseShapes
//Paths Part
let rect = UIBezierPath(rect: CGRect(x: 50, y: 50, width: 50, height: 50))
let oval = UIBezierPath(ovalIn: CGRect(x: 120, y: 120, width: 100, height: 50))
let roundedRect = UIBezierPath(roundedRect: CGRect(x: 200, y: 200, width: 50, height: 50),
cornerRadius: 10.0)
//Shapes
let rectShape = CAShapeLayer()
rectShape.path = rect.cgPath
rectShape.lineWidth = 4.0
rectShape.fillColor = UIColor.clear.cgColor
rectShape.strokeColor = UIColor.orange.cgColor
view.layer.addSublayer(rectShape)
let ovalShape = CAShapeLayer()
ovalShape.path = oval.cgPath
ovalShape.lineWidth = 4.0
ovalShape.fillColor = UIColor.clear.cgColor
ovalShape.strokeColor = UIColor.orange.cgColor
view.layer.addSublayer(ovalShape)
let roundedRectShape = CAShapeLayer()
roundedRectShape.path = roundedRect.cgPath
roundedRectShape.lineWidth = 4.0
roundedRectShape.fillColor = UIColor.clear.cgColor
roundedRectShape.strokeColor = UIColor.orange.cgColor
view.layer.addSublayer(roundedRectShape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment