具有文本样式自定义大小的系统字体

System Font with custom size for text style

目标:

我想知道如何在我的 SwiftUI 应用程序中使用支持动态大小的自定义大小的系统字体(当用户更改设备上的文本大小时,字体大小会动态变化).

问题:

我可以使用标准 .body.title 等系统字体,但我想使用自定义大小,它略有不同,但仍想确保它适用于动态类型

我失败的尝试:

//Font size doesn't change when the user changes his preferred text size on the device
Text("hello")
    .font(.system(size: 14, weight: .bold, design: .default))

注:

我的目标是 iOS 15,我正在寻找符合以下几行的系统字体:

static func custom(_ name: String, size: CGFloat, relativeTo textStyle: Font.TextStyle) -> Font

问题:

没有办法做到这一点,但我意识到其中一种预定义的文本样式符合要求。

有一种方法可以将字体修饰符链接在一起(将字体样式设置为 bold()

示例:

.font(.body.bold())