From 7f7c8b37723da6284447a847e9a80a75ff9407b1 Mon Sep 17 00:00:00 2001 From: Mwai Banda Date: Fri, 21 Jun 2024 22:56:00 -0500 Subject: [PATCH] Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index bf27042c..685a6dfc 100755 --- a/README.md +++ b/README.md @@ -728,6 +728,24 @@ val font: Font = MR.fonts.Raleway.italic.asFont( style = FontStyle.Normal // optional ) ``` +#### SwiftUI + +For SwiftUI, create this `Font` extension: + +```swift +extension Font { + init(resource: KeyPath, withSize: Double = 14.0) { + self.init(MR.fonts()[keyPath: resource].uiFont(withSize: withSize)) + } +} +``` + +Then, you can refer to `FontResource`s directly by their key path, which provides compiler errors for typos or missing resources: + +```swift + Text("Text displayed resource font") + .font(Font(resource: \.raleway_regular, withSize: 14.0)) +``` ### Example 9 - pass colors