Use custom fonts for IOS

Source: Internet
Author: User

1. Add the corresponding font (. ttf or. odf) to the resurce of the project, such as UnidreamLED. ttf (led font)

2. In info. plist, add a Fonts provided by application (the value corresponding to item0 is UnidreamLED. ttf, and add multiple Fonts in sequence)

3. Find UnidreamLED. the font name corresponding to ttf. You can use the following code to print all available font names of the system. Then you need to look for the corresponding font name carefully, here there is a stupid way to compare, that is to say, print out the familyname of all fonts in the system before adding this font, then add this font and print all familynames again, then, you can find the added familyname.

 

NSArray * familyNames = [[NSArray alloc] initWithArray: [UIFont familyNames];

NSArray * fontNames;

NSInteger indFamily, indFont;

For (indFamily = 0; indFamily <[familyNames count]; ++ indFamily)

{

NSLog (@ "Family name: % @", [familyNames objectAtIndex: indFamily]);

FontNames = [[NSArray alloc] initWithArray:

[UIFont fontNamesForFamilyName:

[FamilyNames objectAtIndex: indFamily];

For (indFont = 0; indFont <[fontNames count]; ++ indFont)

{

NSLog (@ "Font name: % @", [fontNames objectAtIndex: indFont]);

}

[FontNames release];

}

[FamilyNames release];

 

3. The next step is to use it. For example, the name of the font corresponding to the font I added is @ "UniDream_LED". When using label. font = [UIFont fontWithName: @ "UniDream_LED" size: 13];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.