Initializer

init(_:)

Gets a font from a platform font instance.

Declaration

init(_ font: CTFont)

Discussion

Initializing Font with platform font instance (CTFont) can bridge SwiftUI Font with NSFont or UIFont, both of which are toll-free bridged to CTFont. For example:

// Use native Core Text API to create desired ctFont.
let ctFont = CTFontCreateUIFontForLanguage(.system, 12, nil)!
// Create SwiftUI Text with the CTFont instance.
let text = Text("Hello").font(Font(ctFont))

See Also

Getting System Fonts

static func system(Font.TextStyle, design: Font.Design) -> Font

Gets a system font with the given style and design.

static func system(size: CGFloat, weight: Font.Weight, design: Font.Design) -> Font

Specifies a system font to use, along with the style, weight, and any design parameters you want applied to the text.

static func custom(String, size: CGFloat) -> Font

Gets a custom font with the given name and size.

enum Font.TextStyle

A dynamic text style to use for fonts.

enum Font.Design

A design to use for fonts.