SwiftUI中文本的自定义字体大小 [英] Custom font size for Text in SwiftUI

查看:128
本文介绍了SwiftUI中文本的自定义字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有一个标签,我想使用中等大小的系统字体,大小为21点.
我创建了一个自定义扩展名,以重复使用创建的字体:

I have a label in my view that I want to use the system font size in medium, with a size of 21 points.
I created a custom extension to re-use the font created:

extension Font {
    static var primaryButton: Font {
        return Font.custom("SFUIDisplay-Light", size: 21)
    }
}

但是,这没有任何效果.我将字符串更改为 HelveticaNeue-UltraLight ,它确实起作用了,所以我猜测 SFUIDisplay-Light 只是错误的字体名称.
在字体书中,它显示为 SFProText-Light ,但这对我也不起作用.

However, this does not have any effect. I changed the string to HelveticaNeue-UltraLight and it did work, so I'm guessing that SFUIDisplay-Light is simply the incorrect font name.
In font book, it says SFProText-Light, but that also did not work for me.

SwiftUI中San Francisco字体的正确字体名称是什么?
或者:如何使用系统字体设置字体大小?

What is the correct font name of the San Francisco font in SwiftUI?
Or: how can I set the font size using the system font?

推荐答案

您可以使用以下方法为系统字体设置显式大小:

You can set an explicit size for the system font with:

.font(.system(size: 60))

这篇关于SwiftUI中文本的自定义字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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