UIFontDescriptor objects provide a mechanism to describe a font with a dictionary of attributes. This font descriptor can be used later to create or modify a
UIFont object. Font descriptors can be archived and unarchived. Font descriptors have a font matching capability, so that you can partially describe a font by creating a font descriptor with, for example, just a family name. You can then find all the available fonts on the system with a matching family name using
- iOS 7.0+
- tvOS 7.0+
- watchOS 2.0+
There are several ways to create a new
UIFontDescriptor object. To take advantage of text styles and respect the user’s current content size category, use
preferredFontDescriptor(withTextStyle:). You can also use
init(name:size:) to create a font descriptor based on either your custom attributes dictionary or on a specific font’s name and size. Alternatively you can use one of the
fontDescriptor… instance methods (such as
withFace(_:)) to create a modified version of an existing descriptor (the receiver). The latter methods are useful if you have an existing descriptor and simply want to change one aspect.
All attributes in the attributes dictionary are optional.