Created
April 12, 2016 00:41
-
-
Save edwardloveall/64a9d828cbcdf751e15fd08caad2ec07 to your computer and use it in GitHub Desktop.
Which way should I draw?
This file contains hidden or 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 | |
| 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