Skip to content

Instantly share code, notes, and snippets.

@ddribin
Created May 7, 2011 12:51
Show Gist options
  • Save ddribin/960471 to your computer and use it in GitHub Desktop.
Save ddribin/960471 to your computer and use it in GitHub Desktop.
//
// ViewA.m
// test
//
// Created by Duncan Wilcox on 5/7/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ViewA.h"
@implementation ViewA
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)drawRect:(NSRect)dirtyRect
{
[NSGraphicsContext saveGraphicsState];
// Set a "baseline" clip of the bounds rect. But by reversing the path, any paths that get
// appended will "punch a hole" in the bounds rect.
NSBezierPath * clipPath = [[NSBezierPath bezierPathWithRect:[self bounds]] bezierPathByReversingPath];
[clipPath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(50, 50, 50, 50)]];
[clipPath appendBezierPath:[NSBezierPath bezierPathWithRect:NSMakeRect(150, 150, 50, 75)]];
[clipPath addClip];
[[NSColor redColor] set];
[[NSBezierPath bezierPathWithRect:self.bounds] fill];
[NSGraphicsContext restoreGraphicsState];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment