Class

UIFont

The UIFont class provides the interface for getting and setting font information. The class 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.

Overview

You do not create UIFont objects using the alloc and init methods. Instead, you use class methods of UIFont, such as preferredFont(forTextStyle:), 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.

Symbols

Creating Fonts

class func preferredFont(forTextStyle: UIFontTextStyle)

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

init?(name: String, size: CGFloat)

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

func withSize(CGFloat)

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

Creating System Fonts

class func systemFont(ofSize: CGFloat)

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

class func systemFont(ofSize: CGFloat, weight: CGFloat)

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

class func boldSystemFont(ofSize: CGFloat)

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

class func italicSystemFont(ofSize: CGFloat)

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

class func monospacedDigitSystemFont(ofSize: CGFloat, weight: CGFloat)

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

Getting the Available Font Names

class func fontNames(forFamilyName: String)

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

Getting Font Name Attributes

var familyName: String

The font family name.

var fontName: String

The font face name.

Getting Font Metrics

var pointSize: CGFloat

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

var ascender: CGFloat

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

var descender: CGFloat

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

var leading: CGFloat

The receiver’s leading information.

var capHeight: CGFloat

The receiver’s cap height information.

var xHeight: CGFloat

The x-height of the receiver.

var lineHeight: CGFloat

The height of text lines (measured in points).

Getting Font Descriptors

var fontDescriptor: UIFontDescriptor

Returns a font descriptor that describes the font.

init(descriptor: UIFontDescriptor, size: CGFloat)

Returns a font matching the given font descriptor.

Relationships

Inherits From