NSFontPanel Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSFontPanel.h
Related sample code

Overview

The NSFontPanel class implements the Font panel—a user interface object that displays a list of available fonts, letting the user preview them and change the font used to display text. The actual changes are made through conversion messages sent to the shared NSFontManager instance. There’s only one Font panel for each application.

Tasks

Getting the Font Panel

Enabling Font Changes

Updating the Font Panel

Converting Fonts

Working in Modal Loops

Setting an Accessory View

Class Methods

sharedFontPanel

Returns the single NSFontPanel instance for the application, creating it if necessary.

+ (NSFontPanel *)sharedFontPanel
Return Value

The NSFontPanel instance for the application.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

sharedFontPanelExists

Returns YES if the shared Font panel has been created, NO if it hasn’t.

+ (BOOL)sharedFontPanelExists
Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

Instance Methods

accessoryView

Returns the receiver’s accessory view.

- (NSView *)accessoryView
Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

isEnabled

Indicates whether the receiver’s Set button is enabled.

- (BOOL)isEnabled
Return Value

YES if the receiver’s Set button is enabled; NO if it isn’t.

Discussion

The receiver continues to reflect the font of the selection for cooperating text objects regardless of this setting.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

panelConvertFont:

Converts the specified font using the settings in the receiver, with the aid of the shared NSFontManager if necessary.

- (NSFont *)panelConvertFont:(NSFont *)aFont
Parameters
aFont

The font to be converted.

Return Value

The converted font, or aFont itself if it can’t be converted.

Discussion

For example, if aFont is Helvetica Oblique 12.0 point and the user has selected the Times font family (and nothing else) in the Font panel, the font returned is Times Italic 12.0 point.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSFontPanel.h

reloadDefaultFontFamilies

Triggers a reload to the default state, so that the delegate is called.

- (void)reloadDefaultFontFamilies
Discussion

This reloading provides the delegate opportunity to scrutinize the default list of fonts to be displayed in the panel.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

setAccessoryView:

Establishes the specified view as the receiver’s accessory view, allowing you to add custom controls to your application’s Font panel without having to create a subclass.

- (void)setAccessoryView:(NSView *)aView
Parameters
aView

The view to set.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

setEnabled:

Specifies whether the receiver’s Set button is enabled.

- (void)setEnabled:(BOOL)flag
Parameters
flag

If YES the Set button is enabled; if NO, it’s disabled.

Discussion

The receiver continues to reflect the font of the selection for cooperating text objects regardless of this setting.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

setPanelFont:isMultiple:

Sets the selected font in the receiver to the specified font.

- (void)setPanelFont:(NSFont *)aFont isMultiple:(BOOL)flag
Parameters
aFont

The font to be selected.

flag

If NO, selects the specified font; otherwise selects no font and displays a message in the preview area indicating that multiple fonts are selected.

Discussion

You normally don’t use this method directly; instead, you send setSelectedFont:isMultiple: to the shared NSFontManager, which in turn invokes this method.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSFontPanel.h

worksWhenModal

Indicates whether the receiver allows fonts to be changed in modal windows and panels.

- (BOOL)worksWhenModal
Return Value

YES, regardless of the setting established using the NSPanel method setWorksWhenModal:.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSFontPanel.h

Constants

Tags of Views in the FontPanel

These constants are obsolete and should not be used. (Deprecated. Use the method and constants described in NSFontPanelValidation Protocol Reference instead.)

enum {
   NSFPPreviewButton = 131,
   NSFPRevertButton = 130,
   NSFPSetButton = 132,
   NSFPPreviewField = 128,
   NSFPSizeField = 129,
   NSFPSizeTitle = 133,
   NSFPCurrentField = 134
};
Constants
NSFPPreviewButton

Show the Preview button.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.

NSFPRevertButton

Show the Revert button.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.

NSFPSetButton

Show the Set button.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.

NSFPPreviewField

Show the Preview field.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.

NSFPSizeField

Show the Size field.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.

NSFPSizeTitle

Show the Size title.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.

NSFPCurrentField

Show the Current field.

Available in OS X v10.0 and later.

Declared in NSFontPanel.h.