Re: Changing the Text Color of an NSMenuItem in an NSPopUpButton?
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.