BPKFont

@interface BPKFont : NSObject

BPKFont is the entry point for the Backpack typography stack. It expose the supported text styles as static methods.

  • Create a dictionary of attributes for a specific text styles. This is some times useful when building custom attributed strings is required.

    Warning

    Prefer using BPKLabel, BPKTextField, or BPKTextView for rendering text when possible.

    Declaration

    Objective-C

    + (nonnull NSDictionary<NSAttributedStringKey, id> *)attributesForFontStyle:
        (BPKFontStyle)fontStyle;

    Swift

    class func makeAttributes(fontStyle: BPKFontStyle) -> [NSAttributedString.Key : Any]

    Parameters

    fontStyle

    The desired fontStyle.

    Return Value

    A dictionary of attributes describing the specified style.

  • Create a dictionary of attributes for a specific text styles. This is some times useful when building custom attributed strings is required.

    Warning

    Prefer using BPKLabel, BPKTextField, or BPKTextView for rendering text when possible.

    Declaration

    Objective-C

    + (nonnull NSDictionary<NSAttributedStringKey, id> *)
        attributesForFontStyle:(BPKFontStyle)fontStyle
                   fontManager:(nonnull BPKFontManager *)fontManager;

    Swift

    class func makeAttributes(fontStyle: BPKFontStyle, fontManager: BPKFontManager) -> [NSAttributedString.Key : Any]

    Parameters

    fontStyle

    The desired fontStyle.

    fontManager

    The fontManager instance to use. By default this is [BPKFontManager sharedInstance].

    Return Value

    A dictionary of attributes describing the specified style.

  • Create a dictionary of attributes for a specific text styles. This is some times useful when building custom attributed strings is required.

    Warning

    Prefer using BPKLabel, BPKTextField, or BPKTextView for rendering text when possible.

    Declaration

    Objective-C

    + (nonnull NSDictionary<NSAttributedStringKey, id> *)
        attributesForFontStyle:(BPKFontStyle)fontStyle
          withCustomAttributes:
              (nonnull NSDictionary<NSAttributedStringKey, id> *)customAttributes;

    Swift

    class func makeAttributes(fontStyle: BPKFontStyle, customAttributes: [NSAttributedString.Key : Any] = [:]) -> [NSAttributedString.Key : Any]

    Parameters

    fontStyle

    The desired fontStyle.

    customAttributes

    Additional attributes to include in the result. Attributes that would break the Backpack type rendering are ignored.

    Return Value

    A dictionary of attributes describing the specified style and custom attributes.

  • Create an attributed string with a specified fontStyle and content. The default Backpack text color will be used.

    Warning

    Prefer using BPKLabel, BPKTextField, or BPKTextView for rendering text when possible.

    Declaration

    Objective-C

    + (nonnull NSAttributedString *)
        attributedStringWithFontStyle:(BPKFontStyle)fontStyle
                              content:(nonnull NSString *)content;

    Swift

    class func makeAttributedString(fontStyle: BPKFontStyle, content: String) -> NSAttributedString

    Parameters

    fontStyle

    The desired fontStyle.

    content

    The content of the attributedString.

    Return Value

    An attributed string with the specified styles.

  • Create an attributed string with a specified fontStyle, content, and text color.

    Warning

    Prefer using BPKLabel, BPKTextField, or BPKTextView for rendering text when possible.

    Declaration

    Objective-C

    + (nonnull NSAttributedString *)
        attributedStringWithFontStyle:(BPKFontStyle)fontStyle
                              content:(nonnull NSString *)content
                            textColor:(nonnull UIColor *)textColor;

    Swift

    class func makeAttributedString(fontStyle: BPKFontStyle, content: String, textColor: Any!) -> NSAttributedString

    Parameters

    fontStyle

    The desired fontStyle.

    content

    The content of the attributedString.

    textColor

    The text color to use.

    Return Value

    An attributed string with the specified styles.

  • Set the fontfaces to use globally.

    Declaration

    Objective-C

    + (void)setFontDefinition:
        (id<BPKFontDefinitionProtocol> _Nullable)fontDefinition;

    Parameters

    fontDefinition

    The new font definition to use when resolving fontface names.

  • Create a UIFont instance for a specific text style.

    Warning

    Prefer using BPKLabel, BPKTextField, or BPKTextView for rendering text when possible.

    Declaration

    Objective-C

    + (nonnull UIFont *)fontForFontStyle:(BPKFontStyle)fontStyle;

    Swift

    class func makeFont(fontStyle: BPKFontStyle) -> UIFont

    Parameters

    fontStyle

    The desired fontStyle.

    Return Value

    An instance of UIFont for the specificed style.