iPhone – Convert CTFont to UIFont?

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.

How do I set bold and italic on UILabel of iPhone/iPad?

Don’t try to play with the font names. Using the font descriptor you need no names: UILabel * label = [[UILabel alloc] init]; // use your label object instead of this UIFontDescriptor * fontD = [label.font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold | UIFontDescriptorTraitItalic]; label.font = [UIFont fontWithDescriptor:fontD size:0]; size:0 means ‘keep the size as is’ With Swift try the … Read more