Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #43 CTFontCreateWithName() warning on iOS 13 #44

Merged

Conversation

ElfSundae
Copy link
Contributor

@ElfSundae ElfSundae commented Sep 24, 2019

Fixed #43

CTFontCreateWithName(".SFUI-Regular") 在 iOS 13 之前会返回 .SFUIText-Regular 这个字体,iOS 13 会返回 Times New Roman 这个字体,并且会输出警告:

CoreText performance note: Client called CTFontCreateWithName() using name ".SFUI-Regular" and got font with PostScript name "TimesNewRomanPSMT". For best performance, only use PostScript names when calling this API.

Ref from: Cocoanetics/DTCoreText#1168 (comment)

This issue behaves as intended.
As mentioned in numerous WWDC sessions, dot-prefixed font names are not to be directly used.
I would also note that UIFont and CTFont are toll-free bridged, so they can be used interchangeably with casts.
Please update your feedback report to let us know if this is still an issue for you.

苹果意思是不要直接使用 (.) 开头的字体名。


修复方案 1: 使用 CTFontCreateWithFontDescriptor 创建 CTFont
修复方案 2:因为 UIFont 和 CTFont 是 toll-free bridged 的,UIFont 其实就是 CTFont,所以可以在任何需要使用 CTFont 的地方类型转换 UIFont 即可: (__bridge CTFontRef)self.font

@xiangwangfeng xiangwangfeng merged commit 55a3c1e into xiangwangfeng:master Sep 25, 2019
@ElfSundae ElfSundae deleted the Fix-CTFontCreateWithName branch September 25, 2019 08:37
@ElfSundae ElfSundae restored the Fix-CTFontCreateWithName branch September 25, 2019 08:47
coderyh pushed a commit to CocoapodsModifiedBranch/YYText that referenced this pull request Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS 13 上有警告
3 participants