Class

UIFont

The interface for getting and setting font information.

Declaration

@interface UIFont : NSObject

Overview

UIFont provides you with access to the font’s characteristics and also provides the system with access to the font’s glyph information, which is used during layout. You use font objects by passing them to methods that accept them as a parameter.

You do not create font objects using the alloc and init methods. Instead, you use class methods of UIFont, such as preferredFontForTextStyle:, to look up and retrieve the desired font object. These methods check for an existing font object with the specified characteristics and return it if it exists. Otherwise, they create a new font object based on the desired font characteristics.

Font objects are immutable and so it is safe to use them from multiple threads in your app.

Topics

Creating Fonts

preferredFontForTextStyle:

Returns an instance of the system font for the specified text style and scaled appropriately for the user's selected content size category.

preferredFontForTextStyle:compatibleWithTraitCollection:

Returns an instance of the system font for the appropriate text style and traits.

Getting a Scaled Font

Scale text in your interface automatically by creating fonts that support Dynamic Type.

Creating Self-Sizing Table View Cells

Create table view cells that support Dynamic Type and use system spacing constraints to adjust the spacing surrounding text labels.

fontWithName:size:

Creates and returns a font object for the specified font name and size.

fontWithDescriptor:size:

Returns a font matching the given font descriptor.

fontWithSize:

Returns a font object that is the same as the receiver but which has the specified size instead.

Creating System Fonts

systemFontOfSize:

Returns the font object used for standard interface items in the specified size.

systemFontOfSize:weight:

Returns the font object used for standard interface items in the specified size and weight.

boldSystemFontOfSize:

Returns the font object used for standard interface items that are rendered in boldface type in the specified size.

italicSystemFontOfSize:

Returns the font object used for standard interface items that are rendered in italic type in the specified size.

monospacedDigitSystemFontOfSize:weight:

Returns the font object used for standard interface items that require fixed distances between digits.

Getting the Available Font Names

familyNames

Returns an array of font family names available on the system.

fontNamesForFamilyName:

Returns an array of font names available in a particular font family.

Getting Font Name Attributes

familyName

The font family name.

fontName

The font face name.

Getting Font Metrics

pointSize

The receiver’s point size, or the effective vertical point size for a font with a nonstandard matrix.

ascender

The top y-coordinate, offset from the baseline, of the receiver’s longest ascender.

descender

The bottom y-coordinate, offset from the baseline, of the receiver’s longest descender.

leading

The receiver’s leading information.

capHeight

The receiver’s cap height information.

xHeight

The x-height of the receiver.

lineHeight

The height of text lines (measured in points).

Getting System Font Information

labelFontSize

Returns the standard font size used for labels.

buttonFontSize

Returns the standard font size used for buttons.

smallSystemFontSize

Returns the size of the standard small system font.

systemFontSize

Returns the size of the standard system font.

Getting Font Descriptors

fontDescriptor

Returns a font descriptor that describes the font.

Relationships

Inherits From

Conforms To

See Also

Fonts

Getting a Scaled Font

Scale text in your interface automatically by creating fonts that support Dynamic Type.

Adding a Custom Font to Your App

Add a custom font to your app and use it in your app’s interface.

UIFontDescriptor

A mechanism to describe a font with a dictionary of attributes.

UIFontDescriptorSymbolicTraits

A symbolic description of the stylistic aspects of a font.

UIContentSizeCategoryAdjusting

A collection of methods that give controls an easy way to adopt automatic adjustment to content category changes.

UIFontMetrics

A utility object for obtaining custom fonts that scale to support Dynamic Type.