英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论