可能存在一种更改菜单栏应用程序标题字体大小的简单方法,使@“title”显示小于(或大于)默认值
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setHighlightMode:YES];
[statusItem setTitle:@"title"];
[statusItem setMenu:statusMenu];
答案 0 :(得分:2)
回应Eugene,为了实现一个图标也是一个标题显示,我使用了一个我打算在下面发布的方法
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
答案 1 :(得分: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];
系统菜单栏不会重新调整大小以容纳太大而无法容纳在其中的字体,因此您无法使字体过大。
答案 2 :(得分:1)
我发现了一种类似的方法
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];
感谢
答案 3 :(得分: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];