Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
I am trying to have the color change on an custom view, as created in the below code.

Code:
#import "myView.h"


@implementation myView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

- (void)drawRect:(NSRect)rect {
	myBounds=[self bounds];
	[[NSColor greenColor]set];
	NSRectFill(myBounds);
}

-(void)resetColor
{
	[[myColor color]set];
	NSRectFill(myBounds);
	[self setNeedsDisplay:YES];
}

@end

myColor is set to the NSColorWell. Basically in the IB there is a color well and a custom view. The custom view starts with green, and I want it to change with changes in the color well.

Appreciate any help.

Adam
 
solved

Below is the solution to the question I posed...

Code:
@implementation AppController

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
	myColor=[[NSColor greenColor]retain];
    return self;
}

-(void)dealloc{
	[myColor release];
	[super dealloc];
}

- (void)drawRect:(NSRect)rect {
	myRect=[self bounds];
	[myColor set];
	NSRectFill(myRect);
}

-(IBAction)setColor:(id)sender{
	[myColor autorelease];
	myColor=[[sender color]retain];
	[self setNeedsDisplay:YES];
}

@end

I basically got it from the DotView sample code that comes with Xcode.

Adam
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.