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
lineMode
line mode of the 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
attributedText
the attrubuted text to style
lineMode
line mode of the 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.
-
Generates the text attributes needed to apply this typographical layout.
These attributes may change (because the font may change) any time there is a change in content size category (Dynamic Type) or legibility weight (Accessibility Bold Text).
Declaration
Swift
func buildAttributes( startingWith additionalAttributes: [NSAttributedString.Key: Any] = [:], lineMode: Typography.LineMode = .single ) -> [NSAttributedString.Key: Any]
Parameters
additionalAttributes
any additional attributes to combine with the typographical attributes. Default =
[:]
lineMode
line mode of the text. Default =
.single
. Paragraph styles will not be applied to single line text.Return Value
the dictionary of attributes needed to style the text.