Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var shapeLayers: [String: CAShapeLayer] = [
- "rectangle": CAShapeLayer(),
- "ellipse1": CAShapeLayer(),
- "ellipse2": CAShapeLayer()...and so on
- ]
- override func awakeFromNib() {
- wantsLayer = true
- for (_, shapeLayer) in shapeLayers {
- shapeLayer.lineWidth = borderWidth
- shapeLayer.strokeColor = ColorScheme.blue.cgColor
- shapeLayer.fillColor = ColorScheme.white.cgColor
- shapeLayer.path = nil
- shapeLayer.lineCap = kCALineCapSquare
- layer?.addSublayer(shapeLayer)
- }
- shapeLayers["rectangle"]?.fillColor = NSColor.clear.cgColor
- }
- override func draw(_ dirtyRect: NSRect) {
- let rectangle = CGMutablePath().addRect(selectionBounds)
- let ellipse1 = CGMutablePath().addEllipse(in: CGRect(origin: somePoint, size: someSize))
- let ellipse2 = CGMutablePath().addEllipse(in: CGRect(origin: somePoint, size: someSize))
- ...and so on
- shapeLayers["rectangle"]?.path = rectangle
- shapeLayers["ellipse1"]?.path = ellipse1
- shapeLayers["ellipse2"]?.path = ellipse2...and so on
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement