I have been trying to use bounds in a custom cell program, as described in a prior post "drawAtPoint". So I wrote a simple customview program, whose code is below...
This works, drawing a simple green box with a diagonal black line in the bottom, left corner. However, when using bounds in the bottom code...
I get the error "invalid initializer". Is bounds inappropriate for drawWithFrame:inView:? Any other ideas? Thanks.
Adam
Code:
@implementation AppController
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)rect {
NSRect myBounds=[self bounds];
[[NSColor greenColor]set];
NSRectFill(myBounds);
NSPoint myPoint1=myBounds.origin;
NSPoint myPoint2=NSMakePoint(50,50);
[[NSColor blackColor]set];
myPath=[NSBezierPath bezierPath];
[myPath setLineWidth:3];
[myPath moveToPoint:myPoint1];
[myPath lineToPoint:myPoint2];
[myPath stroke];
}
@end
This works, drawing a simple green box with a diagonal black line in the bottom, left corner. However, when using bounds in the bottom code...
Code:
-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
NSRect myRect=NSZeroRect;
NSRect myBounds=[self bounds];
NSRect anInsetRect = NSInsetRect(cellFrame,10,10);
NSRect aTextBox = NSMakeRect(anInsetRect.origin.x,anInsetRect.origin.x,25,25);
[[NSColor redColor]set];
NSRectFill(NSInsetRect(cellFrame,4,4));
[string drawInRect:aTextBox withAttributes:attributes];
}
I get the error "invalid initializer". Is bounds inappropriate for drawWithFrame:inView:? Any other ideas? Thanks.
Adam