IPhone - convert CTFont to UIFont?

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

  • Font name
  • Font size
  • Font color
  • Emphasizes
  • Fatty
  • Italics
  • etc.
+5
source share
2 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 font attributes. Bold and italics are part of the font name.

+13
source

With ARC:

 UIFont *uiFont = [UIFont fontWithName:(__bridge NSString *)CTFontCopyPostScriptName(ctFont) size:CTFontGetSize(ctFont)]; 
0
source

All Articles