私が見逃していますか?色は変わらない。setBackgroudColor to NSView
#import "controller.h"
#import "backgroundView.h"
@implementation controller
-(void)awakeFromNib {
backgroundView *background = [[backgroundView alloc] init];
[background setBackgroudColor:[NSColor whiteColor]];
//also didn't work
//[background setBackgroudColor:[[NSColor whiteColor] retain]];
}
@end
//backgroundView.h
#import <Cocoa/Cocoa.h>
@interface backgroundView : NSView{
NSColor *color;
}
-(void)setBackgroudColor:(NSColor*)newColor;
@end
#import "backgroundView.h"
@implementation backgroundView
-(void)dealloc{
[super dealloc];
}
-(void)setBackgroudColor:(NSColor*)newColor{
color = newColor;
[self setNeedsDisplay:YES];
}
-(void)drawRect:(NSRect)rect{
[color setFill];
NSRectFill(rect);
}
@end
私はinitWithFrameをどのように使うべきですか? – user840250
@ user840250: 'init'と同じ方法で使用しますが、ビューにフレームとして持つ矩形を渡します。詳細については、「View Programming Guide」を参照してください。http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaViewsGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40002978およびNSViewクラス参照:http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/cl/NSView –