views:

38

answers:

1

Hi,

I have this idea of having some kind of "badges" in my app. They should be clickable, have an image and a label. That's the easy part. But I also want them to have this little help button in the upper right corner which is also clickable. The help button should just be an image and should of course also be clickable. What would be the best approach of having this small button inside a larger button? Should I have two buttons above each other?

+2  A: 

My suggestion is to bypass trying to beat NSButton into something its not. You can cook up your own "Button" with an NSView or Hierachy of NSViews.

If you are really determined to go the NSButton route perhaps assemble the multiple buttons inside inside an NSView which would be possible inside IB or programatically something like

NSView *container = [[NSView alloc] initWithFrame:NSMakeRect(0,0,100,100)];
NSButton *big = [[[NSButton alloc] initWithFrame:NSMakeRect(0,0,100,100)] autorelease];
NSButton *small = [[[NSButton alloc] initWithFrame:NSMakeRect(80,80,20,20)] autorelease];
[container addSubview:big];
[container addSubview:small];
[small setImage:[NSIMage imageNamed:@"query.png"]];
[big setImage:[NSIMage imageNamed:@"cow.png"]];
[big setTitle:@"cow"];

You'd have to beat the buttons into shape a little more but thats the basics.

Warren Burton
But an NSButton is an NSView, so I could skip the container part.. You're probably right, I should leave NSButton as it is and just use two different ones.
Joos
In terms of lineage, yes, an NSButton is an NSView, but it is also an NSControl, which means it has one or more cells. NSButton itself has only one cell, an NSButtonCell. It's designed to have one cell (versus NSMatrix for example), so you'd have a lot of work to do in order to force it to have two separate cells.If you're not looking to re-use this heavily (ie, dynamically create unknown numbers of it), Warren's suggestion is probably easiest. If you DO want to reuse it, you'll probably want to do it right (using the Control/Cell method found in the docs).
Joshua Nozzi