Skip to content

Commit

Permalink
Merge pull request #738 from MwaiBanda/develop
Browse files Browse the repository at this point in the history
Update README.md(How use fonts in swift ui #729)
  • Loading branch information
Alex009 authored Jun 24, 2024
2 parents 5def4b4 + 7f7c8b3 commit 012eeb9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<MR.fonts, FontResource>, 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

Expand Down

0 comments on commit 012eeb9

Please sign in to comment.