In SwiftUI, is there a way to make the rounded version of the system font the default for all styles? I'm using one of the system styles (.body, .title, .headline, etc) for all text in the app.
For example, I can use this on a single Text view
Text("some text")
.font(.system(.body, design: .rounded))
I'd like to avoid having to update every text view and field in my app like this. Is there some way to tell the environment to use the rounded design by default?
Google Fonts: Varela Round Varela Round is based on the well known font Varela. The rounded corners make it perfect for a soft feel and work great at any size.
SF Pro is the system font in iOS and iPadOS.
SF Pro. This neutral, flexible, sans-serif typeface is the system font for iOS, iPad OS, macOS and tvOS. SF Pro features nine weights, variable optical sizes for optimal legibility, four widths, and includes a rounded variant. SF Pro supports over 150 languages across Latin, Greek, and Cyrillic scripts.
Here is how it is possible to set environment font in root view, all subviews will have it by default.
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("Details")) {
Text("Link")
}
Text("Tap on image to find details")
}
}.environment(\.font, Font.system(.body, design: .rounded))
}
You could create an extension on Font
that has a function that automatically sets the design to being rounded, while still allowing you to set the TextStyle
extension Font {
static func roundedFont(_ style: Font.TextStyle) -> Font {
Font.system(style, design: .rounded)
}
}
Then you would use it like this:
struct ContentView: View {
var body: some View {
Text("Hello").font(.roundedFont(.body))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With