21

How do you set a font to be both bold and italic. There is a boldSystemFontOfSize and italicSystemFoneOfSize, but I can't see the way to set a font to be both italic and bold.

As a second question, is there a way to set an underline on a font, or do you simply draw a line under text.

Xetius
  • 44,755
  • 24
  • 88
  • 123

2 Answers2

58

You have to actually ask for the bold, italic version of a font. For example:

UIFont *myFont = [UIFont fontWithName:@"Helvetica-BoldOblique" size:[UIFont systemFontSize]];

To get a list of everything available on the iPhone, put this little snippet in your applicationDidFinishLaunching: delegate method and look at the log output:

for (NSString *family in [UIFont familyNames]) {
    NSLog(@"%@", [UIFont fontNamesForFamilyName:family]);
}

Note: Some font names say "oblique" - this is the same as italic.

I can't see a built-in way of doing underlines - you may have to draw the line yourself.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • 1
    Excellent little snippet to find all the font names.. :-) – jcpennypincher Oct 03 '11 at 04:40
  • Great. Is there an online reference for the fonts and combinations, other than reverting to log output? – Antony Stubbs Jan 19 '12 at 17:47
  • 4
    Oblique and Italic are ***not*** the same. [Oblique is merely the face slanted](http://en.wikipedia.org/wiki/Oblique_type). It is not really a style but rather a transformation/distortion. Italic is a style that is designed: notice the difference between Times New Roman and Times New Roman Italic (the italic is not just slanted). Most sans-serif fonts do not have italics (just obliques), but a few do, and they are noticeably different than their non-italic kin. – Jakob Jingleheimer Nov 13 '11 at 17:10
0

I recently wrote a blog post about the restrictions of the UIFont API and how to solve it. You can see it at http://eclipsesource.com/blogs/2012/07/26/uifont-from-a-css-definition/

With the code I provide there, you can get your desired system UIFont as easy as:

UIFont *myFont = [FontResolver fontWithDescription:@"font-family: sans-serif; font-weight: bold; font-style: italic;"];

Jordi
  • 617
  • 6
  • 10