I want to set a custom view (not the main one) with a custom NSColor background ([NSColor colorWithPatternImage:[NSImage imageNamed:@"pattern.png"]]
). I've tried making a custom view class:
.h
#import <AppKit/AppKit.h>
@interface CustomBackground : NSView {
NSColor *background;
}
@property(retain) NSColor *background;
@end
.m
#import "CustomBackground.h"
@implementation CustomBackground
@synthesize background;
- (void)drawRect:(NSRect)rect
{
[background set];
NSRectFill([self bounds]);
}
- (void)changeColor:(NSColor*) aColor
{
background = aColor;
[aColor retain];
}
@end
And then in the AppDelegate:
[self.homeView changeColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"pattern.png"]]];
But nothing happens, the color remains the same. What's wrong? Or is there an easier way? NSView doesn't have a backgroundColor
property :(