iPhone - 将CTFont转换为UIFont? [英] iPhone - Convert CTFont to UIFont?

查看:1017
本文介绍了iPhone - 将CTFont转换为UIFont?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将CTFont转换为UIFont而不会丢失任何样式和属性,例如:

I am trying to convert a CTFont to a UIFont without losing any of the styles and attributes such as:


  • 字体名称

  • 字体大小

  • 字体颜色

  • 下划线

  • Bold

  • Italic

  • etc

  • Font Name
  • Font Size
  • Font color
  • Underlines
  • Bold
  • Italic
  • etc

推荐答案

CTFontRef ctFont = ...;
NSString *fontName = [(NSString *)CTFontCopyName(ctFont, kCTFontPostScriptNameKey) autorelease];
CGFloat fontSize = CTFontGetSize(ctFont);
UIFont *font = [UIFont fontWithName:fontName size:fontSize];

颜色和下划线不是字体的属性。粗体和斜体是字体名称的一部分。

Color and underline are not attributes of the font. Bold and italic are part of the font name.

这篇关于iPhone - 将CTFont转换为UIFont?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆