gpt4 book ai didi

objective-c - 如何更改 Objective-C/Cocoa 中状态栏项目标题的颜色?

转载 作者:太空狗 更新时间:2023-10-30 03:51:35 26 4
gpt4 key购买 nike

//Create the NSStatusBar and set its length
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];

[statusItem setHighlightMode:YES];
[statusItem setTitle:@"myTitle"];
[statusItem setToolTip:@"myToolTip"];
[statusItem setMenu:statusMenu];
[statusItem setEnabled:YES];

如何将“myTitle”的颜色改为蓝色?

某些应用程序(如 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 - 如何更改 Objective-C/Cocoa 中状态栏项目标题的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3532712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com