TypographyLayout

public struct TypographyLayout

Typography layout comprises a font and additional typographical information (line height, kerning, etc.). This information is used to render the actual typography using attributed strings. A layout is the output of Typography.generateLayout(...)

  • Font to use (potentially scaled and considering Accessibility Bold Text)

    Declaration

    Swift

    public let font: UIFont
  • Scaled line height to use with this font

    Declaration

    Swift

    public let lineHeight: CGFloat
  • Baseline offset to use with this font (to vertically center the text within the line height)

    Declaration

    Swift

    public let baselineOffset: CGFloat
  • Kerning to apply for letter spacing with this font

    Declaration

    Swift

    public let kerning: CGFloat
  • Paragraph indent to apply

    Declaration

    Swift

    public let paragraphIndent: CGFloat
  • Paragraph spacing to apply

    Declaration

    Swift

    public let paragraphSpacing: CGFloat
  • Text case to apply to text

    Declaration

    Swift

    public let textCase: Typography.TextCase
  • Text decoration to apply

    Declaration

    Swift

    public let textDecoration: Typography.TextDecoration
  • Paragraph style with the correct line height for rendering multi-line text

    Declaration

    Swift

    public let paragraphStyle: NSParagraphStyle
  • Line height multiple to use with this font (to achieve the desired line height)

    Declaration

    Swift

    public var lineHeightMultiple: CGFloat { get }
  • Whether the text needs to styled as an attributed string to display properly.

    If false plain text can be set instead.

    Declaration

    Swift

    var needsStylingForSingleLine: Bool { get }
  • Style plain text using this layout

    Declaration

    Swift

    func styleText(
        _ text: String,
        lineMode: Typography.LineMode,
        additionalAttributes: [NSAttributedString.Key: Any] = [:]
    ) -> NSAttributedString

    Parameters

    text

    the text to style

    isSingleLine

    true for single line text, false for potentially multi-line text. Paragraph styles will not be applied to single line text.

    additionalAttributes

    any additional attributes to apply (e.g. UITextView requires .foregroundColor), default = [:]

    Return Value

    an attributed string containing the styled text.

  • Style attributed text using this layout

    Declaration

    Swift

    func styleAttributedText(
        _ attributedText: NSAttributedString,
        lineMode: Typography.LineMode,
        additionalAttributes: [NSAttributedString.Key: Any] = [:]
    ) -> NSAttributedString

    Parameters

    text

    the text to style

    isSingleLine

    true for single line text, false for potentially multi-line text. Paragraph styles will not be applied to single line text.

    additionalAttributes

    any additional attributes to apply (e.g. UITextView requires .foregroundColor), default = [:]

    Return Value

    an attributed string containing the styled text.