如何设置NSPopupButton菜单项的颜色

编程入门 行业动态 更新时间:2024-10-28 11:32:25
本文介绍了如何设置NSPopupButton菜单项的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个答案,而不是一个问题.在网上搜索时,我只找到了这个问题的真正被歪曲的答案( www.cocoabuilder/archive/cocoa/58379-changing-the-text-color-of-an-nsmenuitem-in-an-nspopupbutton.html ),可以这样更优雅地回答:

This is an answer, rather than a question. Searching online, I only found a really hacked, contorted answer to this question (www.cocoabuilder/archive/cocoa/58379-changing-the-text-color-of-an-nsmenuitem-in-an-nspopupbutton.html), which can be answered more elegantly like so:

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]; }

推荐答案

请注意,上面的问题实际上就是答案.网络上有很多链接,它们基于旧版API的解决方案太复杂,我认为写这篇文章作为参考会很有帮助.

Just a note here that the question above is in fact the answer. There are a lot of links on the web with too complex solutions based on older APIs and I thought it would be helpful to write this posting as a reference.

更多推荐

如何设置NSPopupButton菜单项的颜色

本文发布于:2023-08-06 03:36:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1309795.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置   菜单项   颜色   NSPopupButton

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!