How do I create an NSFont that is both Bold and Italic?

See NSFontManager and -convertFont:toHaveTrait:

For more detailed information, I would suggest reading the Font Handling Guide and specifically the section titled Converting Fonts Manually.

Note, that the font you are using needs to have some version of it with the traits you are asking for, otherwise, you will get back a font, but without the requested trait.

If, eventually, you are seeking to add an italic trait to a font that doesn't have one, check out:

How do I get Lucida Grande italic into my application?


Verdana-BoldItalic.

(The actual name of the bold-italic variant of the font depends on the family, and some font doesn't have bold-italic, Use a NSFontDescriptor with -fontDescriptorWithSymbolicTraits: to get the exact bold italic font.)


This works:

NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSFont *boldItalic = [fontManager fontWithFamily:@"Verdana"
                                          traits:NSBoldFontMask|NSItalicFontMask
                                          weight:0
                                            size:75];

Tags:

Fonts

Cocoa