- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我试图用下载的字体绘制一些文本。我查看了 API 文档并搜索了 Web。我找到了一个解决方案,但问题是它仅适用于 CoreGraphics
级别的框架。所以我寻找一种将CGFont
转换为UIFont
的方法,但是没有办法做到这一点。
我意识到 UIFont
和 CGFont/CTFont
是完全分开的,即使它们是从同一个字体文件创建的。 CGFont
和 CTFont
可以相互转换,但是对于 UIFont
,唯一的方法是使用它的名称和大小等属性重新创建。并且适用的代码也分开了。
例如,CATextLayer
仅接受 CGFont
/CTFont
— 不接受 UIFont
。但是所有 UIKit
控件只接受 UIFont
。
为什么会存在这种分离?还是我错了? (有什么方法可以在 UIKit
类中使用下载的字体?)
最佳答案
简短的回答:“只有 Apple 人才知道”
更详细的答案,在挖掘(逆向)框架之后:
UIKit.framework
根本不使用 CGFont
类型UIKit.framework
使用 CoreText CTFont
和 GSFont
...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
andCoreGraphics
frameworks, via the obscurGraphicsServices
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, andUIKit
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/
我正在使用以下代码生成 PDF,但它会导致内存泄漏,有人可以帮忙吗?代码如下。 - (void)drawText:(NSString*)textToDraw inFrame:(CGRect)frame
我正在尝试在 iPhone 应用程序中使用 CTFont。我有:- 添加了核心文本框架 添加了#import“CoreText/CoreText”。到我尝试在其中使用 CTFont 的文件。 但是编译
我试图在不丢失任何样式和属性的情况下将 CTFont 转换为 UIFont,例如: 字体名称 字体大小 字体颜色 下划线 粗体 斜体 等等 最佳答案 CTFontRef ctFont = ...; N
我有一个 CTFontRef,如何获取字符串形式的字体名称? 最佳答案 阅读此 http://developer.apple.com/library/mac/#documentation/Carbon
我正在使用应用于 CATextLayer 的自定义字体。我正在使用此处找到的教程和示例代码。 http://www.freetimestudios.com/2010/09/13/custom-font
我试图用下载的字体绘制一些文本。我查看了 API 文档并搜索了 Web。我找到了一个解决方案,但问题是它仅适用于 CoreGraphics 级别的框架。所以我寻找一种将CGFont转换为UIFont的
我正在尝试将一些代码移植到使用 UIFont 和 CTFont 的 Swift,并且(成功地,在 Objective-C 中)使用简单的桥接转换从一个到另一个,反之亦然。 例如,考虑这段代码(在 UI
我正在处理仅从资源加载 TTF。 This question帮助我回答了第 1 部分。但现在我需要 CGFont 或 CTFont 中的 NSFont。 这仅适用于 Mac 应用程序。 最佳答案 如何
我是一名优秀的程序员,十分优秀!