• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?


  • Subject: Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
  • From: mmalcolm crawford <email@hidden>
  • Date: Thu, 16 May 2002 23:07:42 -0700

On Thursday, May 16, 2002, at 02:37 PM, email@hidden wrote:

what happens if you set the item title to an NSAttributedString? You can set the foreground and background colors of one, and that might give you what you need.

You can't do that, unfortunately, it seems the title has to be an NSString.
And NSMenuItems don't have NSMenuItemCells either, so you can't set it there either.

What you can do is the following -- I write it last night, but was too embarrassed to post it. I guess I ran out of shame today! :-)

Summary: You can't set the string, but you can set an icon for each item...

mmalc


NSArray *itemArray = [popup itemArray];
int i;
NSDictionary *attributes = [NSDictionary
dictionaryWithObject:[NSColor redColor]
forKey:NSForegroundColorAttributeName];

for (i = 0; i < [itemArray count]; i++) {
NSMenuItem *item = [itemArray objectAtIndex:i];

NSAttributedString *as =
[[NSAttributedString alloc]
initWithString:[item title]
attributes:attributes];

NSImage *image = [[NSImage alloc] initWithSize:
NSMakeSize(90,20)];

[image lockFocus];
[as drawAtPoint:NSMakePoint(3,0)];
[image unlockFocus];

[item setImage:image];
[item setTitle:@""];
[item setTag:i];
[image release];
}
_______________________________________________
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.

  • Follow-Ups:
    • Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
      • From: Richard Kendall Wolf <email@hidden>
    • Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
      • From: mmalcolm crawford <email@hidden>
    • Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
      • From: Nicholas Riley <email@hidden>
References: 
 >Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton? (From: email@hidden)

  • Prev by Date: Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
  • Next by Date: Re: creating 'omni like' disk images
  • Previous by thread: Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
  • Next by thread: Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
  • Index(es):
    • Date
    • Thread