Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set System to always use Rounded Font?

Tags:

swiftui

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?

like image 784
radicalappdev Avatar asked Nov 10 '19 15:11

radicalappdev


People also ask

What is the rounded font called?

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.

What is iOS default font?

SF Pro is the system font in iOS and iPadOS.

What is Apple system font?

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.


2 Answers

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))
}
like image 196
Asperi Avatar answered Sep 22 '22 14:09

Asperi


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))
    }
}
like image 39
Andrew Avatar answered Sep 24 '22 14:09

Andrew