Re: programmatically drawing an NSImageView in an NSView subclass
Re: programmatically drawing an NSImageView in an NSView subclass
- Subject: Re: programmatically drawing an NSImageView in an NSView subclass
- From: Shawn Erickson <email@hidden>
- Date: Sat, 10 Jan 2004 11:56:25 -0800
On Jan 10, 2004, at 11:31 AM, Benjamin Salanki wrote:
hi,
i want to draw some NSImageViews in my NSView subclass.
i use the following code in my drawRect: method:
- (void)drawRect:(NSRect)rect
{
//drawing code here
int numberOfFiles = [_files count];
int i;
for(i=0;i<numberOfFiles;i++)
{
NSImageView* theView = [[NSImageView alloc]
initWithFrame:NSMakeRect(15+(i%3)*85, 15+(i/3)*72, 70.00, 56.00)];
[theView setImageFrameStyle:NSImageFramePhoto];
[theView setImageAlignment:NSImageAlignCenter];
[theView setImageScaling:NSScaleProportionally];
[theView setImage:[[NSImage alloc] initWithContentsOfFile:[_files
objectAtIndex:i]]];
[theView setTag:i];
[theView setTarget:self];
[theView setAction:@selector(what:)];
}
}
the calculations get done and everything, CPU cycles get eaten, but the
view does not display the imageViews. I tried to replace the code and
draw simple rects with NSBezierPath, and that works like a charm.
any ideas?
What are you trying to do exactly? Not in code but what do you want the
end visual result to be and what items are or are not controls?
You are creating a NSImageView which is a NSControl subclass yet you
are not adding them to a containing view so they will not be displayed
(their draw methods will not be called). You should not attempt to
create such items in you draw routine but instead when your view
sub-class is initialized and/or as images are added to custom view. In
fact if your custom view contains nothing but some type of matrix of
image views or other standard view classes you do not need to override
the default drawRect method.
Anyway you may want to consider using a NSMatrix of NSImageViews or not
using image views but directly drawing the images yourself. We cannot
help with this end of things without knowing what the end goal is for
your application.
-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.