Created
September 23, 2015 17:08
-
-
Save oxUnd/68dec4557b52de648599 to your computer and use it in GitHub Desktop.
Custom View for cocoa
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
- (void)drawRect:(CGRect) rect { | |
// If you plan to do more drawing later, it's a good idea | |
// to save the graphics state before clipping. | |
[NSGraphicsContext saveGraphicsState]; | |
long r = random(); | |
long g = random(); | |
long b = random(); | |
NSColor *color = [NSColor colorWithRed: (r * 1.0/(r + g + b)) green: (g * 1.0 / (r + g + b)) blue: (b * 1.0 / (r + g + b)) alpha: 1.0]; | |
[color set]; | |
[[self window] setBackgroundColor:color]; | |
NSBezierPath *path = [NSBezierPath bezierPath]; | |
[path moveToPoint: NSMakePoint(0, rect.size.height)]; | |
[path lineToPoint: NSMakePoint(0, 0)]; | |
int zeroOne = 0; | |
float x, y; | |
for (int i = 0; i < (int) rect.size.width / 10; i++) { | |
if (zeroOne == 1) { | |
y = 0; | |
zeroOne = 0; | |
} else { | |
zeroOne = 1; | |
y = 10; | |
} | |
x = 10 * i; | |
[path lineToPoint: NSMakePoint(x, y)]; | |
} | |
[path lineToPoint:NSMakePoint(rect.size.width, (zeroOne == 0 ? 10 : 0))]; | |
[path lineToPoint:NSMakePoint(rect.size.width, rect.size.height)]; | |
NSShadow * shadow = [[NSShadow alloc] init]; | |
[shadow setShadowColor:[NSColor grayColor]]; | |
[shadow setShadowBlurRadius:10.0]; | |
[shadow set]; | |
[path fill]; | |
[NSGraphicsContext restoreGraphicsState]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment