italic, bold and underlined font on iPhone

后端 未结 2 694
Happy的楠姐
Happy的楠姐 2020-12-02 15:00

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 b

相关标签:
2条回答
  • 2020-12-02 15:14

    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.

    0 讨论(0)
  • 2020-12-02 15:18

    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;"];

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