Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. var shapeLayers: [String: CAShapeLayer] = [
  2. "rectangle": CAShapeLayer(),
  3. "ellipse1": CAShapeLayer(),
  4. "ellipse2": CAShapeLayer()...and so on
  5. ]
  6.  
  7. override func awakeFromNib() {
  8. wantsLayer = true
  9.  
  10. for (_, shapeLayer) in shapeLayers {
  11. shapeLayer.lineWidth = borderWidth
  12. shapeLayer.strokeColor = ColorScheme.blue.cgColor
  13. shapeLayer.fillColor = ColorScheme.white.cgColor
  14. shapeLayer.path = nil
  15. shapeLayer.lineCap = kCALineCapSquare
  16. layer?.addSublayer(shapeLayer)
  17. }
  18.  
  19. shapeLayers["rectangle"]?.fillColor = NSColor.clear.cgColor
  20. }
  21.  
  22. override func draw(_ dirtyRect: NSRect) {
  23. let rectangle = CGMutablePath().addRect(selectionBounds)
  24. let ellipse1 = CGMutablePath().addEllipse(in: CGRect(origin: somePoint, size: someSize))
  25. let ellipse2 = CGMutablePath().addEllipse(in: CGRect(origin: somePoint, size: someSize))
  26. ...and so on
  27.  
  28. shapeLayers["rectangle"]?.path = rectangle
  29. shapeLayers["ellipse1"]?.path = ellipse1
  30. shapeLayers["ellipse2"]?.path = ellipse2...and so on
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement