• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 在旧金山使用 fontWithSize API

[复制链接]
菜鸟教程小白 发表于 2022-12-13 11:35:48 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

iOS 9 中的新 San Francisco 字体通过调整跟踪以及在 SF Display 和 SF Text 之间动态切换,针对将要使用的大小进行了优化。在 WWDC session #804 中指出,开发人员不应通过尝试使用 fontWithName 初始化 UIFont 来使用 San Francisco,例如:

UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [UIFont fontWithNameriginalFont.fontName size:44];

这是因为在使用 fontWithName API 时,系统无法针对新大小优化字体。

建议从原始字体中获取 UIFontDescriptor 并使用新字体创建新字体,如下所示:

UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [UIFont fontWithDescriptorriginalFont.fontDescriptor size:44];

但是,他们没有提及以下是否允许优化:

UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [originalFont fontWithSize:44];

我的问题是,fontWithSize API 的行为是否类似于 fontWithName API 或 fontWithDescriptor API - 它是否会产生优化的字体新尺寸还是没有?



Best Answer-推荐答案


我可以确认 fontWithSize 确实以新大小创建了优化的字体。

Printing description of originalFont:
<UICTFont: 0x7f8d9ba85340> font-family: ".SFUIText-Regular"; font-weight: normal; font-style: normal; font-size: 11.00pt

Printing description of newFont:
<UICTFont: 0x7f8d9ba7fe70> font-family: ".SFUIDisplay-Regular"; font-weight: normal; font-style: normal; font-size: 44.00pt

关于ios - 在旧金山使用 fontWithSize API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426341/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap