NSButtonCells in Custom View
NSButtonCells in Custom View
- Subject: NSButtonCells in Custom View
- From: Michael Becker <email@hidden>
- Date: Tue, 12 Oct 2004 18:07:07 +0200
Hi!
I want to draw a matrix of buttons in a custom view that need to re-organise whenever the view's size changes. I've taken the advice to use NSButtonCells instead of NSButtons. However, these NSButtonCells don't do anything. They're displayed, I connected their targets and actions but they don't respond to mouse clicks in whatsoever way.
I tried the same thing with NSButtons, by adding them as subviews to my custom view and on each drawRect: I checked the view's size and re-organised the subviews' frame rects. The target/action/highlighting worked wonderfully. But using NSButtons produced a strange behavior of the buttons as they would "lag behind" on a resize (I blame that on the subview-principle, somehow...)
Code snippet #1: Adding another button...
NSButtonCell *button = [[ NSButtonCell alloc] init];
[ button setButtonType:NSMomentaryLightButton];
[ button setBordered:YES];
[ button setBezelStyle:NSRegularSquareBezelStyle];
[ button setTarget:_pvButtonTarget];
[ button setAction:_pvButtonAction];
[ buttons addObject:button];
[ button release];
Code snippet #2: part of the drawRect method:
for (i=0; i<[ buttons count]; i++) {
[[ buttons objectAtIndex:i] drawWithFrame:NSMakeRect(x,y,BUTTON_WIDTH,BUTTON_HEIGHT) inView:self];
x += BUTTON_CELL_WIDTH;
if (x+BUTTON_CELL_WIDTH >= mySize.width) {
x = 0;
y += BUTTON_CELL_HEIGHT;
}
}
So what do I have to do to get the NSButtonCells to work?
Cheers,
Michael _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden