4

I would like to open the NSFontPanel with a font (in the following example Helevtica) selected initially. I mean that when the font panel shows up, the collection and family values are selected. Here is my code:

NSFontManager * fontManager = [NSFontManager sharedFontManager];
[fontManager setTarget:self];
[fontManager setSelectedFont:[NSFont fontWithName:@"Helvetica" size:150.0]; isMultiple:NO];
[fontManager orderFrontFontPanel:self];

Why does the Helvetica font not show up selected in the font panel?

I am also using NSFontPanelValidation protocol, here is the code:

- (NSUInteger)validModesForFontPanel:(NSFontPanel *)fontPanel
{
    return NSFontPanelFaceModeMask | NSFontPanelCollectionModeMask | NSFontPanelUnderlineEffectModeMask | NSFontPanelStrikethroughEffectModeMask;
}
AmaltasCoder
  • 1,123
  • 3
  • 17
  • 35

1 Answers1

3

On a fresh appkit project, your code works for me. I'm calling it from the main delegate. Helvetica at 150 pts gets selected when I open it without using validation.

enter image description here

the Reverend
  • 12,305
  • 10
  • 66
  • 121