Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Connecting the Font Menu in Interface Builder 3
Q: How do I connect items in the Font or Format menu in Interface Builder 3?
A: Interface Builder 3 provides two standard menus, the Font menu and Format menu, which contain the items most users expect for font interactions. These include displaying the Font Panel, making selected text bold, italic, or underlined, showing the Color Panel, modifying text size, text alignment, kerning and ligature options, and more. AppKit includes a shared NSFontManager instance (a singleton) for each application. Cocoa's NSFontManager provides many of the actions in the font menu; the rest are handled by the first responder.
There are three main steps:
Adding the Font Menu
Open your application's Main Menu nib in Interface Builder 3.
In IB's Library panel, find the Font (or Format) Menu Item.
Drag it to your Main Menu.
Add the NSFontManager shared instance.
This creates a custom object in your NIB file of type NSFontManager. At runtime, AppKit will create a single shared instance of NSFontManager. When the object in your nib is unarchived, the NSFontManager class will swap this instance out for the shared instance.
In IB's Library panel, find "Object"
Drag it to your nib.
Select the new Object.
Open IB's "Identity" Inspector (command-6)
In the custom class box, enter "NSFontManager"
Connect the menu items
Some menu items in the Font and Format menus should be connected to the First Responder proxy, others to the Font Manager. The following table contains a reference of all the connections that have to be made for the Format menu to be fully functional. The Font menu is a subset of the Format menu.
Menu Item | Destination | Selector |
---|---|---|
Font Menu |
|
|
Show Fonts | Font Manager | orderFrontFontPanel: |
Bold | Font Manager | addFontTrait: |
Italic | Font Manager | addFontTrait: |
Underline | First Responder | underline: |
Bigger | Font Manager | modifyFont: |
Smaller | Font Manager | modifyFont: |
Kern Menu |
|
|
Use Default | First Responder | useStandardKerning: |
Use None | First Responder | turnOffKerning: |
Tighten | First Responder | tightenKerning: |
Loosen | First Responder | loosenKerning: |
Ligature Menu |
|
|
Use Default | First Responder | useStandardLigatures: |
Use None | First Responder | turnOffLigatures: |
Use All | First Responder | useAllLigatures: |
Baseline Menu |
|
|
Use Default | First Responder | unscript: |
Superscript | First Responder | superscript: |
Subscript | First Responder | subscript: |
Raise | First Responder | raiseBaseline: |
Lower | First Responder | lowerBaseline: |
Show Colors | First Responder | orderFrontColorPanel: |
Copy Style | First Responder | copyFont: |
Paste Style | First Responder | pasteFont: |
Text Menu |
|
|
Align Left | First Responder | alignLeft: |
Center | First Responder | alignCenter: |
Justify | First Responder | alignJustified: |
Align Right | First Responder | alignRight: |
Show Ruler | First Responder | toggleRuler: |
Copy Ruler | First Responder | copyRuler: |
Paste Ruler | First Responder | pasteRuler: |
Related Documentation
Document Revision History
Date | Notes |
---|---|
2008-01-21 | New document that how to connect and configure the Font/Format menus in Interface Builder 3. |
Copyright © 2008 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2008-01-21