如何在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
相关产品推荐
相关产品推荐

