Re: Setting image one pulldown popup button

Christiaan Hofman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Dec 7, 2009, at 18:36, Matt Neuburg wrote:

> On or about 12/7/09 5:19 AM, thus spake "Christiaan Hofman"
> <[email protected]>:
> 
>> However, the sample code does not have a popup like I have, without border and
>> only an image. That still does not work.
> 
> Well, as I said, it works for me. I made a project containing this code.
> This is the project's ONLY code. And I see the image and no border:
> 
> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
>    NSPopUpButton* overflowButton = [[NSPopUpButton alloc]
> initWithFrame:NSMakeRect(20.0, 80.0, 100.0, 42.0) pullsDown:YES];
>    [overflowButton setBordered:NO];
>    [[overflowButton cell] setArrowPosition:NSPopUpNoArrow];
>    [[overflowButton cell] setAltersStateOfSelectedItem:NO];
>    [[overflowButton cell] setBackgroundStyle:NSBackgroundStyleRaised];
>    [overflowButton addItemWithTitle:@""];
>    [[overflowButton itemAtIndex:0] setImage:[NSImage
> imageNamed:@"mailTypeASCII.tiff"]];
>    [[window contentView] addSubview:overflowButton];
> }
> 
> That is effectively YOUR code, except that I made sure the image is properly
> referenced, and I made the button rect large enough to see the image. I got
> the image from Apple's example.
> 
> Plus I later added a few more addItemWithTitle lines, and the button does
> definitely work as a popup button with a menu.
> 
> Just so you can see I'm not cheating in some way, here is the code you claim
> to be using, for comparison with mine:
> 
>>> overflowButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 17,
> 10) pullsDown:YES];
>>> [overflowButton setBordered:NO];
>>> [[overflowButton cell] setArrowPosition:NSPopUpNoArrow];
>>> [[overflowButton cell] setAltersStateOfSelectedItem:NO];
>>> [[overflowButton cell] setBackgroundStyle:NSBackgroundStyleRaised];
>>> [overflowButton addItemWithTitle:@""];
>>> [[overflowButton itemAtIndex:0] setImage:[NSImage imageNamed:@"Overflow"]];
> 
> I merely copied it into a new project and made the small changes you can see
> above. m.
> 
> -- 
> matt neuburg, phd = [email protected], http://www.tidbits.com/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
> AppleScript: the Definitive Guide, 2nd edition
> http://www.tidbits.com/matt/default.html#applescriptthings
> Take Control of Exploring & Customizing Snow Leopard
> http://tinyurl.com/kufyy8
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.com

I already explained in my previous email. The size is important, and note that (17,10) is the size of the Overflow image I'm using. This makes NSPopUpButton useless in practice for of borderless pulldowns (e.g. Mail's mailbox action button). Moreover, though it works in 10.6.2, it does not in some earlier version (I don't remember if it was 10.6.1 or 10.6.0). 

Christiaan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.