在iOS7及之后的iOS系统版本,TextKit框架中提供了一个新的类UIFontDescriptor。 简单理解,UIFontDescriptor类是专门用来描述字体的,其中提供了许多方法可以直接创建出某种字体,也可以对字体进行设置和调整。动态字体也由这个类来创建。 使用UIFontDescriptor类中的如下方法可以创建动态字体: //创建动态字体的字体描述类实例 + (UIFontDescriptor *)preferredFontDescriptorWithTextStyle 类 UIFontDescriptor类可以直接通过字体名称来进行创建: //通过字体名称和字号尺寸来进行UIFontDescriptor对象的创建 + (UIFontDescriptor UIFontDescriptorInherits From NSObject UIFontDescriptor NSObject UIFontDescriptor Conforms To CVarArgT
UIFontDescriptorInherits From NSObject UIFontDescriptor NSObject UIFontDescriptor Conforms To CVarArgT UIFontDescriptorInherits From NSObject UIFontDescriptor NSObject UIFontDescriptor Conforms To CVarArgT
除了指定的大小 - (UIFont *)fontWithSize:(CGFloat)fontSize; //通过描述信息返回字体 7.0后可用 + (UIFont *)fontWithDescriptor:(UIFontDescriptor *)descriptor size:(CGFloat)pointSize NS_AVAILABLE_IOS(7_0); //返回字体的描述信息,7.0后可用 - (UIFontDescriptor *
可通过字体描述符( UIFontDescriptor )动态生成所需字重,减少预加载的字体数量;对于非启动必需的艺术字体,可注册字体文件路径而不立即加载,直到首次渲染时再通过 CTFontManagerRegisterFontsForURL