简体   繁体   English

如何在 IOS13 中找到这个与字体相关的 coretext 警告的来源?

[英]How can i find the source of this font-related coretext warning in IOS13?

Working on an update of my app i notice that i get tons of warnings in the log when running the app in Xcode 11.2 on IOS13.在更新我的应用程序时,我注意到在 IOS13 上的 Xcode 11.2 中运行应用程序时,我在日志中收到大量警告。

CoreText note: Client requested name ".SFUI-Regular", it will get TimesNewRomanPSMT rather than the intended font. CoreText 注意:客户端请求的名称“.SFUI-Regular”,它将获得 TimesNewRomanPSMT 而不是预期的字体。 All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:].所有系统 UI 字体访问都应通过适当的 API,例如 CTFontCreateUIFontForLanguage() 或 +[UIFont systemFontOfSize:]。

I dug around a bit and found this quote from WWDC:我挖了一下,发现了 WWDC 的这句话:

As mentioned in numerous WWDC sessions, dot-prefixed font names are not to be directly used.正如许多 WWDC 会议中所提到的,不能直接使用带点前缀的字体名称。

I am myself almost exclusively using IB and nibs to set fonts for textfields etc., and there is no reference to "SFUI-Regular" in my code anywhere, so i am not sure how to find the actual reason for these warnings (i have something like 20-30 rows of these in the logs).我自己几乎完全使用 IB 和 nibs 为文本字段等设置 fonts,并且在我的代码中没有任何地方提到“SFUI-Regular”,所以我不确定如何找到这些警告的实际原因(我有日志中有 20-30 行这样的内容)。

Does anyone have any tips on how i can find where the warning comes from, and how to fix it?有没有人对我如何找到警告的来源以及如何解决它有任何提示?

There is another output in console, you can try to add a symbolic breakpoint控制台还有一个output,可以试试加个符号断点

CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug. CoreText 注释:在 CTFontLogSystemFontNameRequest 上设置断点进行调试。

I started experiencing this warning in the console starting with Xcode 11, with both MacOS and iOS targets.我开始在控制台中遇到此警告,从 Xcode 11 开始,同时具有 MacOS 和 iOS 目标。

You will receive ".SFUI-Regular" from UIFont.systemFont(ofSize: X).fontName .您将从UIFont.systemFont(ofSize: X).fontName收到“.SFUI-Regular”。 The warning will then occur if you try to instantiate using UIFont(name: fontName, size: size) .如果您尝试使用UIFont(name: fontName, size: size)进行实例化,则会出现警告。

In my case I am letting the user customize the display font, but the default was ".SFUI-Regular", so I have changed that to "TimesNewRomanPSMT"就我而言,我让用户自定义显示字体,但默认值为“.SFUI-Regular”,因此我将其更改为“TimesNewRomanPSMT”

let defaultFont = UIFont.systemFont(ofSize: X).fontName

// replace with
let defaultFont = "TimesNewRomanPSMT"

UIFont(name: defaultFont, size: size)

Having the same issue and no reference to dot-prefixed font in my code either.有同样的问题,也没有在我的代码中引用点前缀字体。 Set a symbolic breakpoint but nothing of any use设置一个符号断点但没有任何用处

For me, it turns out it was a third-party library that has not been updated in a while that was the culprit.对我来说,原来是第三方库有一段时间没有更新是罪魁祸首。

I put a breakpoint as the user clatt suggested and found the source.我按照用户 clatt 的建议设置了一个断点并找到了源代码。 In my case it was TOMSMorphingLabel .就我而言,它是TOMSMorphingLabel

let fontCT = CTFontCreateUIFontForLanguage(.label, fontSize as CGFloat, nil)
attrStr.addAttribute(.font, value: fontCT as Any, range: NSMakeRange(0, text.count))

solution for uifont issue for ios 13 ios 13 的 uifont 问题的解决方案

I got this if I blindly used:如果我盲目使用,我会得到这个:

UIFont(name: fontName, size: fontSize) UIFont(名称:字体名称,大小:字体大小)

and the fontName was "System Font", which was part of a list I got from:并且字体名称是“系统字体”,这是我从中获得的列表的一部分:

let fontFamilyNames = UIFont.familyNames.sorted()让 fontFamilyNames = UIFont.familyNames.sorted()

Workaround was to check the name.解决方法是检查名称。

let isSystemFont = fontName == "System Font"
let useFont = isSystemFont ? UIFont.systemFont(ofSize: fontSize) : UIFont(name: fontName, size: fontSize) ?? UIFont.systemFont(ofSize: fontSize)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM