将系统设置为始终使用圆形字体? [英] Set System to always use Rounded Font?

查看:29
本文介绍了将系统设置为始终使用圆形字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SwiftUI 中,有没有办法让系统字体的圆角版本成为所有样式的默认值?我正在为应用中的所有文本使用一种系统样式(.body、.title、.headline 等).

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?

推荐答案

这里是如何在根视图中设置环境字体,默认情况下所有子视图都会有它.

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))
}

这篇关于将系统设置为始终使用圆形字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆