簡體   English   中英

獲取Cocoa for NSMenuItem的默認字體名稱?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM