Re: Drawing an image in a CustomView
Re: Drawing an image in a CustomView
- Subject: Re: Drawing an image in a CustomView
- From: Scott Anguish <email@hidden>
- Date: Tue, 15 Jan 2002 02:07:03 -0500
On Monday, January 14, 2002, at 11:01 PM, Enigmarelle Development wrote:
(code snipped)
- (void)drawRect:(NSRect)rect {
// Drawing code here.
image = [[NSImage alloc] initWithContentsOfFile:@"macosxlogo.gif"];
[simpleImageView setImage:image];
}
Replace 'simpleImageView' with 'self' above & all looks like it should
work. (haven't tried it though.) If all you want to do is display an
image though, use a borderless NSImageView and set its image in IB.
Part of learning Cocoa is learning to be lazy ;)
it'll compile/run ... it won't actually DRAW anything.. and it'll
leak BAD.. :-(
move the image line to the initWithFrame, use a different variable
to temporarily hold the image than the instance variable (or you can
junk the entire accessor approach, but its an excellent habit to get
into)
use [self setImage:theImage] in the initWithFrame if you decide to
keep it
actually draw the image in drawRect:
[image compositeToPoint:[self bounds].origin
operation:NSCompositeSourceOver];