Re: How to make a NSMatrix with NSImageCell's ??
Re: How to make a NSMatrix with NSImageCell's ??
- Subject: Re: How to make a NSMatrix with NSImageCell's ??
- From: John Pannell <email@hidden>
- Date: Sun, 20 Oct 2002 21:39:59 -0600
Hi Ivan-
Brian has started you down the right path, perhaps I can add enough to
get you going the rest of the way. I have an app with similar
functionality; here's what I did:
1. I subclassed NSMatrix so that I could perform some customization
(i.e. Use image cells configured how I want them, add some special event
handling to the matrix, handle resizing of the matrix of images in a
more "performance sensitive" way). Here is the initWithFrame: override
in my subclass:
- (id)initWithFrame:(NSRect)frameRect
{
// create the cell prototype and style it
id cell = [[PSMActionImageCell alloc] init];
[cell setImageAlignment:NSImageAlignCenter];
[cell setImageFrameStyle:NSImageFrameGrayBezel];
[cell setImageScaling:NSScaleProportionally];
[cell setEnabled:YES];
// create the actual matrix of buttons
[super initWithFrame:frameRect
mode:NSListModeMatrix
prototype:cell
numberOfRows:0
numberOfColumns:4];
// put a white background behind cells
[self setDrawsBackground:YES];
[self setBackgroundColor:[NSColor whiteColor]];
// configure the size and spacing of buttons
// use the width of the superview (the scroller)
[self setCellSize:NSMakeSize(100,100)];
[self setIntercellSpacing:NSMakeSize(0,0)];
[cell release];
return self;
}
2. In IB, I put a custom View on my window and set its class to the one
I created (I had called it ThumbnailMatrix)
3. Voila! I had a matrix of image cells. Actually, I had also created
my own image cell subclass (PSMActionImageCell in the code above) that
added the features of an action cell - needed this in my app, and it
sounds like you might too.
4. In my app controller, I added rows to the matrix as I enumerated
over the array that was the source of the images. You'll need to look
at addRow: and sizeToCells: in the NSMatrix documentation. Put the
images in the cells via something like [[theImageMatrix cellAtRow:row
column:column] setImage:theImage].
I just re-read this and realized that I have glossed over a lot that I
would normally cover while answering; sorry for keeping this so brief.
If you need more help, email me off list and I can send you some of the
source files.
Despite some shortcomings (many of which have been discussed on this
list), the Apple/O'Reilly book "Learning Cocoa" does have a good example
of creating a subclass of NSMatrix to provide custom behavior and
configuration. It is part of the creation of the "ToDo" application.
Hope this helps!
John P.
On Sunday, October 20, 2002, at 04:50 PM, Ivan Subotic wrote:
But what I would like to do is fill the NSMatrix dynamicaly with an
array
that has NSImageCells.
Let me explaine what I would like to build:
I want to make a window which displays thumbnails from a directory.
Thats
why it has to be dynamic. I'm not even shure if NSMatrix is the right
way of
doing it.
Any sugestions?
Did you try something like:
In Interface Buidler drag a window out of the pallete. Drag a custom
view into the window. In the inspector choose custom class and select
NSMatrix. Then drag imageviews into the custom view or drag one
imageview and dupe it there.
ber
On Saturday, October 19, 2002, at 09:58 PM, Ivan Subotic wrote:
Hi
I'm having a problem making a NSMatrix with NSImageCells. Is it
possible to
do it with the interface builder, or do I have to do it
programaticaly.
A short description would be helpfull :-)
TIA
Ivan Subotic
_______________________________________________
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.
_______________________________________________
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.
_______________________________________________
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.