Skip to content

Instantly share code, notes, and snippets.

@edwardloveall
Created April 12, 2016 00:41
Show Gist options
  • Select an option

  • Save edwardloveall/64a9d828cbcdf751e15fd08caad2ec07 to your computer and use it in GitHub Desktop.

Select an option

Save edwardloveall/64a9d828cbcdf751e15fd08caad2ec07 to your computer and use it in GitHub Desktop.
Which way should I draw?
import Cocoa
class ViewA: NSView {
override func drawRect(rect: NSRect) {
let context = NSGraphicsContext.currentContext()?.CGContext
CGContextSetRGBFillColor(context, 0, 0, 0, 1)
CGContextFillRect(context, bounds)
CGContextSetRGBFillColor(context, 1, 0, 0, 1)
CGContextAddArc(context, 50, 50, 25, 0, CGFloat(M_PI * 2), 1)
CGContextFillPath(context)
}
}
class ViewB: NSView {
override func drawRect(rect: NSRect) {
NSColor.blackColor().setFill()
NSBezierPath.fillRect(bounds)
let box = NSRect(x: 25, y: 25, width: 50, height: 50)
let circlePath = NSBezierPath()
circlePath.appendBezierPathWithOvalInRect(box)
NSColor.redColor().setFill()
circlePath.fill()
}
}
let frame = NSMakeRect(0, 0, 100, 100)
ViewA(frame: frame)
ViewB(frame: frame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment