Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Convert CTFont to UIFont?

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

  • Font Name
  • Font Size
  • Font color
  • Underlines
  • Bold
  • Italic
  • etc
like image 344
aryaxt Avatar asked Jul 16 '11 02:07

aryaxt


1 Answers

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.

like image 108
omz Avatar answered Oct 05 '22 11:10

omz