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
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.
With ARC:
UIFont *uiFont = [UIFont fontWithName:(__bridge NSString *)CTFontCopyPostScriptName(ctFont) size:CTFontGetSize(ctFont)];
来源:https://stackoverflow.com/questions/6714858/iphone-convert-ctfont-to-uifont