如何在objective-CC++ocoa中更改状态栏项目标题的颜色?

如何在objective-CC++ocoa中更改状态栏项目标题的颜色?,第1张

概述//Create the NSStatusBar and set its lengthstatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];[statusItem setHighlightMode:YES];[statusItem setTitl
//Create the Nsstatusbar and set its lengthstatusItem = [[[Nsstatusbar systemStatusbar] statusItemWithLength:NSSquareStatusItemLength] retain];[statusItem setHighlightmode:YES];[statusItem setTitle:@"myTitle"];[statusItem settooltip:@"mytooltip"];[statusItem setMenu:statusMenu];[statusItem setEnabled:YES];

如何改变“myTitle”的颜色f.e.蓝色?像PeerGuardian这样的应用程序在其列表被禁用时将其状态栏项目标题更改为红色,所以我想这在某种程度上是可能的.

谢谢!

解决方法 使用NsstatusItem的-setAttributedTitle方法,并为其提供适当颜色的NSAttributedString:

NSDictionary *TitleAttributes = [NSDictionary dictionaryWithObject:[NScolor bluecolor] forKey:NSForegroundcolorAttributename];NSAttributedString* blueTitle = [[NSAttributedString alloc] initWithString:@"myTitle" attributes:TitleAttributes];statusItem = [[[Nsstatusbar systemStatusbar] statusItemWithLength:NSSquareStatusItemLength] retain];[statusItem setAttributedTitle:blueTitle];[blueTitle release];
总结

以上是内存溢出为你收集整理的如何在objective-C/C++ocoa中更改状态栏项目标题的颜色?全部内容,希望文章能够帮你解决如何在objective-C/C++ocoa中更改状态栏项目标题的颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1004881.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存