1

可能存在更改菜单栏应用程序标题字体大小的简单方法,使@“title”显示比默认值更小(或更大)

statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];

[statusItem setHighlightMode:YES];
[statusItem setTitle:@"title"];
[statusItem setMenu:statusMenu];
4

4 回答 4

3

回应尤金,为了实现图标也有标题显示,我使用了我计划在下面发布的方法

statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];

NSFont *font = [NSFont fontWithName:@"LucidaGrande" size:12.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"title" attributes:attrsDictionary];

NSBundle *bundle = [NSBundle mainBundle];

statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
statusHighlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon-alt" ofType:@"png"]];

[statusItem setImage:statusImage];
[statusItem setAlternateImage:statusHighlightImage];
[statusItem setHighlightMode:YES];
[statusItem setAttributedTitle:attrString];
[statusItem setMenu:statusMenu];

我计划发布一个教程链接,它体面地解释了某些代码的大部分原因 http://www.sonsothunder.com/devres/revolution/tutorials/StatusMenu.html

于 2013-09-09T20:50:10.417 回答
2

我发现了一个类似的方法

statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];

NSFont *font = [NSFont fontWithName:@"LucidaGrande" size:12.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"title" attributes:attrsDictionary];

[statusItem setHighlightMode:YES];
[statusItem setAttributedTitle:attrString];
[statusItem setMenu:statusMenu];

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/AttributedStrings/Tasks/CreatingAttributedStrings.html

谢谢

于 2013-06-30T06:17:26.513 回答
1

您可以按如下方式更改状态项的字体:

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];

NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:@"MyTitle"];
[attrStr setAttributes:@{NSFontAttributeName: [NSFont systemFontOfSize:22]}
                 range:NSMakeRange(0,7)];

[statusItem setHighlightMode:YES];
[statusItem setAttributedTitle:attrStr];

系统菜单栏不会重新调整大小以适应太大而无法容纳其中的字体,因此您不能使字体太大。

于 2013-06-24T02:45:37.580 回答
0

两个答案都对我不起作用=(状态栏有相同的字体

NSFont *font = [NSFont fontWithName:@"Lucida Grande" size:9.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"title" attributes:attrsDictionary];


statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
NSImage *statusImage = [NSImage imageNamed:@"icon.png"];
[statusItem setImage:statusImage];
NSImage *altStatusImage = [NSImage imageNamed:@"icon.png"];
[statusItem setAlternateImage:altStatusImage];
[statusItem setHighlightMode:YES];
[statusItem setAttributedTitle:attrString];
[statusItem setTitle:@"Loading..."];
[statusItem setMenu:statusMenu];
于 2013-09-07T19:15:28.233 回答