Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created Jun 16, 2020
Embed
What would you like to do?
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