系统字体(SF Pro?),在使用.custom时加上.rounded — 适用于iOS 15

huangapple go评论108阅读模式
英文:

System font (SF Pro?), .rounded when using .custom — for iOS 15

问题

直到现在,我一直在使用固定的字体大小,像这样:

Text("Example")
    .font(.system(size: 24, weight: .medium, design: .rounded))

我现在正在尝试实现动态字体大小,以便随不同的辅助功能模式进行缩放。我找到了这个链接,其中提到:“如果您使用的是 iOS 14 或更高版本,您会发现您的自定义字体会自动缩放,无需进一步操作”。这对我来说确实有效,但现在我找不到一种方法来将字体设置为 .rounded(因为 .fontDesign 需要 iOS 16+,而我正在针对 iOS 15)。

另外,对于系统字体,我应该使用什么作为第一个参数(字体名称)?我尝试过 UIFont.systemFont 等,但没有成功。我甚至不确定 SF Pro 是否是正确的名称:

Text("Example")
    .font(.custom("SF Pro", size: 24))

也许我在某些其他不清楚的方面完全做错了。这是否是用于辅助功能的动态字体大小的正确方法 — 使用 .custom,指定默认大小(用于默认字体大小),然后让 iOS 根据需要缩放它?

英文:

until now I have been using fixed font sizes, like this:

Text("Example")
    .font(.system(size: 24 weight: .medium, design: .rounded))

I am now trying to implement dynamic font sizes, so it scales with different accessibility modes. I found this, which says "If you’re using iOS 14 or later you’ll find your custom fonts scale automatically with no further work from you". This does work for me, but now I can't find a way to make the font .rounded (as .fontDesign is iOS 16+, and I am targeting iOS 15).

Also, what should I use as the first parameter (font name) for the system font? I tried UIFont.systemFont, etc, which didn't work. I'm not even 100% sure SF Pro is the correct name here:

Text("Example")
    .font(.custom("SF Pro", size: 24))

Perhaps I'm doing this completely wrong in some other way that is not clear to me. Is this the correct approach to dynamic font sizing for accessibility — to use .custom, specify a default size (for the default type size), and let iOS scale this accordingly?

答案1

得分: 0

我意识到,如果我移除.weight参数并使用.largeTitle等,它就可以正常工作,并且我可以分别设置字重:

.font(.system(.largeTitle, design: .rounded))
.fontWeight(.bold)

我如何设置.largeTitle.body等的默认大小?

英文:

I realised that if I remove the .weight parameter and use .largeTitle, etc, it works — and I can set the weight separately:

.font(.system(.largeTitle, design: .rounded))
.fontWeight(.bold)

How do I set the default sizes of .largeTitle, .body, etc?

huangapple
  • 本文由 发表于 2023年1月9日 14:12:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75053717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定