Hi,
I'm using a NSComboBox and want to mark some of the items in the popup list appear in red. I couldn't find a proper Method to override in NSComboBoxCell. Any idea?
Hi,
I'm using a NSComboBox and want to mark some of the items in the popup list appear in red. I couldn't find a proper Method to override in NSComboBoxCell. Any idea?
How about using NSCell
's -setAttributedStringValue:
method? Just create an NSAttributedString
which has the color you want set for the NSForegroundColorAttributeName
key and you should be good to go.
You'll need to modify the popup button's menu items directly, but it's not very hard. You shouldn't even need to subclass, you can do it all from the controller.
NSMenu *menu = [popUpButton menu];
NSMenuItem *item = [menu itemWithTag:100];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:[item title] attributes:attributes];
[item setAttributedTitle:string];
You'll probably want to copy attributes from the existing attributed string title so the font and size remain the same, but that should get you started.