Last active
December 18, 2016 05:45
-
-
Save robertmryan/b7a180aac09dcfc3b07c202cd89d786f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
@IBDesignable | |
class HolyView: NSView { | |
override func draw(_ dirtyRect: NSRect) { | |
super.draw(dirtyRect) | |
let center1 = NSPoint(x: bounds.size.width * 0.3 + bounds.origin.x, y: bounds.size.height / 2 + bounds.origin.y) | |
let radius1 = bounds.size.width / 6 | |
let center2 = NSPoint(x: bounds.size.width * 0.7 + bounds.origin.x, y: bounds.size.height / 2 + bounds.origin.y) | |
let radius2 = bounds.size.width / 6 | |
let path = NSBezierPath() | |
path.move(to: NSPoint(x: center1.x, y: center1.y - radius1)) | |
path.appendArc(withCenter: center1, radius: radius1, startAngle: -90, endAngle: 270) | |
path.move(to: NSPoint(x: center2.x, y: center2.y - radius2)) | |
path.appendArc(withCenter: center2, radius: radius2, startAngle: -90, endAngle: 270) | |
path.move(to: bounds.origin) | |
path.appendRect(NSInsetRect(bounds, 10, 10)) | |
path.close() | |
path.windingRule = .evenOddWindingRule | |
NSColor.blue.setFill() | |
path.fill() | |
NSColor.black.setStroke() | |
path.lineWidth = 5 | |
path.stroke() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This illustrates
move(to:)
to avoid lines between the various subpaths:Clearly, you're probably not drawing the paths, so it's not necessary, but it's useful when drawing boundaries like this.