How to add your own fonts for iOS ------ lable sets custom Fonts
Today I made a lable program for custom fonts. The design said that the system does not conform to the artistic atmosphere, so I designed a Custom font and added it to the project.
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 Aragones. TTF you just added.
Yes. You can add multiple names. You can write the corresponding font name when using it.
3. You can use it directly in your project. Xx. font = [UIFont fontWithName: @ Aragones 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:
Aragones. TTF, Add Fonts provided by application
Running the above program will list
2012-10-20 21:56:21.321 MyAnimationTest[5397:c07] Family name: HAKUYOGuiFanZi35002012-10-20 21:56:21.321 MyAnimationTest[5397:c07] Font name: HAKUYOGuiFanZi35002012-10-20 21:56:21.322 MyAnimationTest[5397:c07] Family name: Didot2012-10-20 21:56:21.322 MyAnimationTest[5397:c07] Font name: Didot-Italic2012-10-20 21:56:21.322 MyAnimationTest[5397:c07] Font name: Didot2012-10-20 21:56:21.323 MyAnimationTest[5397:c07] Font name: Didot-Bold2012-10-20 21:56:21.323 MyAnimationTest[5397:c07] Family name: Bodoni 72 Smallcaps2012-10-20 21:56:21.323 MyAnimationTest[5397:c07] Font name: BodoniSvtyTwoSCITCTT-Book
If the Family name of the font is used instead of the file name of the font, you will not be able to see the effect if you make a mistake. If you use a font alone, you can also use the font name, depending on your preferences.
Effect: