iPhone - Convert CTFont to UIFont?

后端 未结 2 1638
無奈伤痛
無奈伤痛 2020-11-30 14:18

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
相关标签:
2条回答
  • 2020-11-30 14:44

    With ARC:

    UIFont *uiFont = [UIFont fontWithName:(__bridge NSString *)CTFontCopyPostScriptName(ctFont) size:CTFontGetSize(ctFont)];
    
    0 讨论(0)
  • 2020-11-30 14:53
    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.

    0 讨论(0)
提交回复
热议问题