You need to enable JavaScript to run this app. 如何在Swift中实现SF Pro Rounded字体文本?
优惠活动
大模型
产品
解决方案
定价
更多

如何在Swift中实现SF Pro Rounded字体文本?

在SwiftUI中设置SF Pro Rounded字体

要让你的Text组件使用SF Pro Rounded字体,不能直接依赖系统预设的.largeTitle这类样式(它们默认调用标准SF Pro字体),需要通过Font.custom()方法指定SF Pro Rounded的具体字体名称。

修改后的代码示例

Text("Levitate")
    .font(Font.custom("SFProRounded-Semibold", size: 34)) // largeTitle默认对应字号为34
    .foregroundColor(Color.white)
    .multilineTextAlignment(.center)

适配系统动态字体的写法

如果想保留系统动态字体特性(比如跟随系统字体大小设置自动调整),可以基于系统样式的字号来创建自定义字体:

Text("Levitate")
    .font(
        Font.custom(
            "SFProRounded-Semibold",
            size: UIFont.preferredFont(forTextStyle: .largeTitle).pointSize
        )
    )
    .foregroundColor(Color.white)
    .multilineTextAlignment(.center)

SF Pro Rounded字重对应名称

根据需求替换以下字体名称即可切换字重:

  • 常规:SFProRounded-Regular
  • 中等:SFProRounded-Medium
  • 半粗:SFProRounded-Semibold
  • 加粗:SFProRounded-Bold

内容的提问来源于stack exchange,提问作者steeezyboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 19:18:19