Cocoa provides support for programmatically getting font information using the NSFont class. You can apply fonts as attributes to strings or use them to set the default font in the current context. The Cocoa text system also uses font objects for formatting text. You request NSFont objects from Cocoa using the name and size of the font you want, as shown in the following example.
NSFont* font1= [NSFont fontWithName:@"Helvetica" size:9.0]; |
NSFont* font2 = [NSFont fontWithName:@"Helvetica Bold" size:10.0]; |
The NSFont class does not provide a programmatic way to modify other text attributes, such as the character spacing and text drawing mode. Cocoa does, however, provide a system Font panel that you can display to the user. From this panel, the user can make changes to the current font attributes. You can also set most text options using the Cocoa text system, which is described in “Advanced Text Drawing.”
Although you usually specify font attributes directly when drawing NSString and NSAttributedString objects, you can also change the font and font size information in the current graphics state. To change these values, you create an NSFont object and invoke its set method.
For information about working with fonts and font objects, see Font Handling. For information about how to display the Font panel, see Font Panel.
Last updated: 2007-10-31