Skip navigation.
 
mlRe: NSMenuItem and images
FROM : Kristopher Matthews
DATE : Mon Apr 28 20:22:43 2008

// size the image for our menu
   NSSize size;
   size.width = [[NSFont menuFontOfSize:0] pointSize];
   size.height = size.width;

This works like a charm.

On Apr 28, 2008, at 9:39 AM, Adam R. Maxwell wrote:

>
> On Apr 28, 2008, at 7:18 AM, glenn andreas wrote:
>

>>
>> On Apr 27, 2008, at 11:44 PM, Adam R. Maxwell wrote:
>>

>>> Sure, but you have no way of knowing what the correct size is for 
>>> an NSMenuItem (assuming you want a normal size).  I set all menu 
>>> item images to 16x16 since that looks approximately correct, but 
>>> I'd rather have NSMenuItem draw the image at the correct size, or 
>>> have something like -[NSMenuItem height] to get a nominal, future-
>>> proof size.

>>
>>
>> NSMenuItem doesn't actually have a "correct size" - it calculates 
>> its size based on its contents.  So a large font in an attributed 
>> string title will cause it to have a larger size, as will setting 
>> an image (or NSView for Leopard).
>>
>> So asking the menu item for the size isn't the right way to do it - 
>> it's going to say "as large as it needs to be to hold everything". 
>> You don't care how big it is - you want the image to look good with 
>> the menu text.
>>
>> Instead, it since you want the image to match the size of the text, 
>> so you'd probably be better off by getting the font and measuring 
>> its line height.

>
> Thanks; I never thought of taking that route!  In case anyone else 
> has trouble finding the menu font and size, you can use [NSFont 
> menuFontOfSize:0] to get the correct font.
>
> --
> adam
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlNSMenuItem and images Kristopher Matthew… Apr 28, 01:03
mlRe: NSMenuItem and images Seth Willits Apr 28, 06:29
mlRe: NSMenuItem and images Adam R. Maxwell Apr 28, 06:44
mlRe: NSMenuItem and images Kristopher Matthew… Apr 28, 13:39
mlRe: NSMenuItem and images Hamish Allan Apr 28, 14:12
mlRe: NSMenuItem and images Kristopher Matthew… Apr 28, 14:28
mlRe: NSMenuItem and images Adam R. Maxwell Apr 28, 15:21
mlRe: NSMenuItem and images Hamish Allan Apr 28, 15:33
mlRe: NSMenuItem and images Kristopher Matthew… Apr 28, 15:41
mlRe: NSMenuItem and images Adam R. Maxwell Apr 28, 15:48
mlRe: NSMenuItem and images Hamish Allan Apr 28, 16:00
mlRe: NSMenuItem and images Adam R. Maxwell Apr 28, 16:07
mlRe: NSMenuItem and images glenn andreas Apr 28, 16:18
mlRe: NSMenuItem and images Adam R. Maxwell Apr 28, 16:39
mlRe: NSMenuItem and images Kristopher Matthew… Apr 28, 20:22