gpt4 book ai didi

ios - 为什么 UIFont 和 CGFont/CTFont 完全分离?

转载 作者:技术小花猫 更新时间:2023-10-29 10:16:09 24 4
gpt4 key购买 nike

我试图用下载的字体绘制一些文本。我查看了 API 文档并搜索了 Web。我找到了一个解决方案,但问题是它仅适用于 CoreGraphics 级别的框架。所以我寻找一种将CGFont转换为UIFont的方法,但是没有办法做到这一点。

我意识到 UIFontCGFont/CTFont 是完全分开的,即使它们是从同一个字体文件创建的。 CGFontCTFont 可以相互转换,但是对于 UIFont,唯一的方法是使用它的名称和大小等属性重新创建。并且适用的代码也分开了。

例如,CATextLayer 仅接受 CGFont/CTFont — 不接受 UIFont。但是所有 UIKit 控件只接受 UIFont

为什么会存在这种分离?还是我错了? (有什么方法可以在 UIKit 类中使用下载的字体?)

最佳答案

简短的回答:“只有 Apple 人才知道”

更详细的答案,在挖掘(逆向)框架之后:

  • UIKit.framework 根本不使用 CGFont 类型
  • UIKit.framework 使用 CoreText CTFontGSFont...
  • GSFont 来自... GraphicsServices 私有(private)框架
  • GraphicsServices...使用CGFont

所以这是我的猜测(可能完全错误):

  • UIFont > GSFont(私有(private))> CGFont
  • UIKit > GraphicsServices > CoreGraphics :

    At least Concerning fonts, Apple engineers have set up an abstraction layer between UIKit and CoreGraphics frameworks, via the obscur GraphicsServices one.

  • iOS > iOS (私有(private))> Mac OSX :

    Why they did this, I would say CoreGraphics, which comes from Mac OSX, wasn't optimal for iOS devices, and UIKit being iOS only, they added a layer between both apis. Or more generally they plan one day to separate completely UIKit from CoreGraphics... iOS from Mac OSX... Who knows! The apple folks does, my short answer :)

关于在 UIKit 中使用自定义字体,您可能有兴趣阅读 this .

关于ios - 为什么 UIFont 和 CGFont/CTFont 完全分离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5799128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com