[英]Get default font name in Cocoa for NSMenuItem?
I am using NSAttributed NSString in my NSMenuItem, but it's Font is changed as compare to default font, I wants to use default font for Attributed string. 我在我的NSMenuItem中使用NSAttributed NSString,但它的字体与默认字体相比发生了变化,我想使用默认字体作为属性字符串。
Can any one explain, how to find or fetch the default Font for NSMenuItems. 任何人都可以解释,如何查找或获取NSMenuItems的默认字体。
Right now I am using this : 现在我正在使用这个:
NSDictionary *attributes = @{
NSFontAttributeName: [NSFont fontWithName:@"Helvetica" size:14],
NSForegroundColorAttributeName: [NSColor blackColor],
NSParagraphStyleAttributeName:paragraphStyle
};
Thanks 谢谢
To get the default font of an NSMenuItem
just use the method [NSFont menuBarFontOfSize:0]
. 要获取
NSMenuItem
的默认字体,只需使用方法[NSFont menuBarFontOfSize:0]
。
NSDictionary *attributes = @{ NSFontAttributeName: [NSFont menuBarFontOfSize:0],
NSForegroundColorAttributeName: [NSColor blackColor],
NSParagraphStyleAttributeName: paragraphStyle };
which is easier in all ways. 这在各方面都比较容易。
I got the solution, I used this 我得到了解决方案,我使用了这个
NSFont *oldFont = [menu font];
NSLog(@"%@",oldFont.familyName);
and used like this 并使用这样的
NSDictionary *attributes = @{
NSFontAttributeName:[NSFont fontWithName:@"Lucida Grande" size:14],
NSForegroundColorAttributeName: [NSColor blackColor],
NSParagraphStyleAttributeName:paragraphStyle
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.