How to add your own fonts in iOS crazy explanation

Source: Internet
Author: User

How to add your own fonts in iOS crazy explanation

1. The first step is to find the ttf format of the font you want to use. Add to the resouce directory of your project.

2. In the plist of the project, AddRow, "Fonts provided by application", and then add the key as item0, and the value is the testFont. ttf you just added.

In this way, you can add more than one font name.

3. You can use it directly in your project. Xx. font = [UIFont fontWithName: @ testFont size: 20.0];

 

Note:

Add this code in the program and run it,


NSArray * familyNames = [[NSArray alloc] initWithArray: [UIFont familyNames];
NSArray * fontNames;
NSInteger indFamily, indFont;
NSLog (@ [familyNames count] ==%d, [familyNames count]);
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];

View the console. The above programs will list all Fonts, including the Fonts added by "Fonts provided by application", but note that the names may differ greatly and you need to find them by yourself.
Example:
TestFont. ttf, Add Fonts provided by application
Running the above program will list

21:56:21. 321 MyAnimationTest [5397: c07] Family name: HAKUYOGuiFanZi3500
21:56:21. 321 MyAnimationTest [5397: c07] Font name: HAKUYOGuiFanZi3500
21:56:21. 322 MyAnimationTest [5397: c07] Family name: Didot
21:56:21. 322 MyAnimationTest [5397: c07] Font name: Didot-Italic
21:56:21. 322 MyAnimationTest [5397: c07] Font name: Didot
21:56:21. 323 MyAnimationTest [5397: c07] Font name: Didot-Bold
21:56:21. 323 MyAnimationTest [5397: c07] Family name: Bodoni 72 Smallcaps
21:56:21. 323 MyAnimationTest [5397: c07] Font name: BodoniSvtyTwoSCITCTT-Book

To use the Family name of the font, rather than the file name of the font, you will not be able to see the effect if you make a mistake.

Note that the added font file xxx. ttf is added to "Copy Boundle Resources" as follows:

 

It is best to use it directly.

 

Effect:

 

 

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.