这是一个答案,而不是一个问题.在线搜索,我发现这个问题的答案真的被黑了,扭曲了(http://www.cocoabuilder.com/archive/cocoa/58379-changing-the-text-color-of-an-nsmenuitem-in-an- nspopupbutton.html),可以更优雅地回答:
NSArray *itemArray = [scalePopup itemArray];
int i;
NSDictionary *attributes = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSColor redColor], NSForegroundColorAttributeName,
[NSFont systemFontOfSize: [NSFont systemFontSize]],
NSFontAttributeName, nil];
for (i = 0; i < [itemArray count]; i++) {
NSMenuItem *item = [itemArray objectAtIndex:i];
NSAttributedString *as = [[NSAttributedString alloc]
initWithString:[item title]
attributes:attributes];
[item setAttributedTitle:as];
}
Run Code Online (Sandbox Code Playgroud)
在网上搜索,我只找到了这个问题的一个非常被黑的、扭曲的答案,可以更优雅地回答,如下所示:
NSArray *itemArray = [scalePopup itemArray];
int i;
NSDictionary *attributes = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSColor redColor], NSForegroundColorAttributeName,
[NSFont systemFontOfSize: [NSFont systemFontSize]],
NSFontAttributeName, nil];
for (i = 0; i < [itemArray count]; i++) {
NSMenuItem *item = [itemArray objectAtIndex:i];
NSAttributedString *as = [[NSAttributedString alloc]
initWithString:[item title]
attributes:attributes];
[item setAttributedTitle:as];
}
Run Code Online (Sandbox Code Playgroud)