[英]Get default font name in Cocoa for NSMenuItem?
我在我的NSMenuItem中使用NSAttributed NSString,但它的字體與默認字體相比發生了變化,我想使用默認字體作為屬性字符串。
任何人都可以解釋,如何查找或獲取NSMenuItems的默認字體。
現在我正在使用這個:
NSDictionary *attributes = @{
NSFontAttributeName: [NSFont fontWithName:@"Helvetica" size:14],
NSForegroundColorAttributeName: [NSColor blackColor],
NSParagraphStyleAttributeName:paragraphStyle
};
謝謝
要獲取NSMenuItem
的默認字體,只需使用方法[NSFont menuBarFontOfSize:0]
。
NSDictionary *attributes = @{ NSFontAttributeName: [NSFont menuBarFontOfSize:0],
NSForegroundColorAttributeName: [NSColor blackColor],
NSParagraphStyleAttributeName: paragraphStyle };
這在各方面都比較容易。
我得到了解決方案,我使用了這個
NSFont *oldFont = [menu font];
NSLog(@"%@",oldFont.familyName);
並使用這樣的
NSDictionary *attributes = @{
NSFontAttributeName:[NSFont fontWithName:@"Lucida Grande" size:14],
NSForegroundColorAttributeName: [NSColor blackColor],
NSParagraphStyleAttributeName:paragraphStyle
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.