4

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.

Can any one explain, how to find or fetch the default Font for NSMenuItems.

Right now I am using this : sample image

 NSDictionary *attributes = @{
                                 NSFontAttributeName: [NSFont fontWithName:@"Helvetica" size:14],
                                 NSForegroundColorAttributeName: [NSColor blackColor],
                                 NSParagraphStyleAttributeName:paragraphStyle

                                 };

Thanks

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48

2 Answers2

4

To get the default font of an NSMenuItem just use the method [NSFont menuBarFontOfSize:0].

NSDictionary *attributes = @{ NSFontAttributeName: [NSFont menuBarFontOfSize:0],
                              NSForegroundColorAttributeName: [NSColor blackColor],
                              NSParagraphStyleAttributeName: paragraphStyle };

which is easier in all ways.

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
1

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

                                 };
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48