/ Published in: Objective C

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
{ NSColor *startingColor; NSColor *endingColor; int angle; } // Define the variables as properties @property(assign) int angle; @end @implementation ColorGradientView // Automatically create accessor methods @synthesize startingColor; @synthesize endingColor; @synthesize angle; - (id)initWithFrame:(NSRect)frame; { if (self = [super initWithFrame:frame]) { [self setEndingColor:nil]; [self setAngle:270]; } return self; } - (void)drawRect:(NSRect)rect; { if (endingColor == nil || [startingColor isEqual:endingColor]) { // Fill view with a standard background color [startingColor set]; NSRectFill(rect); } else { // Fill view with a top-down gradient // from startingColor to endingColor initWithStartingColor:startingColor endingColor:endingColor] autorelease]; [aGradient drawInRect:[self bounds] angle:angle]; } } { [startingColor autorelease]; startingColor = [newColor retain]; [self setNeedsDisplay:YES]; } { [endingColor autorelease]; endingColor = [newColor retain]; [self setNeedsDisplay:YES]; } - (void)dealloc; { [self setStartingColor:nil]; [self setEndingColor:nil]; [super dealloc]; } @end
Comments
