Use custom fonts in iOS and custom fonts in iOS

Source: Internet
Author: User

Use custom fonts in iOS and custom fonts in iOS

1. Make sure you have the font file (. ttf or. odf) under the Resources of your project ).

 

2. In the Info. create a new line in the plist file and add the key: UIAppFonts. The type is Array or Dictionary. Create another key-Value Pair under UIAppFonts, the key is Item 0, and the Value is XXX. ttf (font name, string type), you can add multiple, use the corresponding font name.

 

3. When the font is used in your project, xx. font = [UIFont fontWithName: @ "XXX" size: 20.0.

 

Ios code  
  1. -(Void) viewDidLoad {
  2. NSString * imageName = @ "grid.png ";
  3. UIImageView * imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: imageName];
  4. ImageView. frame = CGRectMake (20, 20,250,250 );
  5. UILabel * test = [[UILabel alloc] init];
  6. Test. frame = CGRectMake (95,215,200, 50 );
  7. Test. font = [UIFont fontWithName: @ "HAKUYOGuiFanZi3500" size: 30];
  8. Test. text = @ "Original Image ";
  9. Test. backgroundColor = [UIColor clearColor];
  10. [ImageView addSubview: test];
  11. [Test release];
  12. [Self. view addSubview: imageView];
  13. [ImageView release];
  14. }

 


How does IOS customize UIFont fonts?

Do you mean dayoou.com? The font provided by the iOS system is limited. When customizing UIFont fonts, I usually use the following method: font files (. ttf format or. odf format) Method 1: add the corresponding font (. ttf or. odf) to resurce of the project, use the FontLabel library in cocos2d, FontLabel inherits from UILabel, just like UILabel. FontName directly uses the name of the added resource. Method 2: 1. Add the corresponding font (. ttf or. odf) to the project resurce, such as my. ttf. 2. In info. plist, add a Fonts provided by application (the value corresponding to item0 is my. ttf, and add multiple Fonts in sequence ). 3. When using aLabel. font = [UIFontfontWithName: @ "XXX" size: 30]; note that XXX is not necessarily my, here is return to castle. You can use the following methods to view familyname and fontname: NSArray * familyNames = [UIFont familyNames]; for (NSString * familyName in familyNames) {printf ("Family: % s \ n ", [familyName UTF8String]); NSArray * fontNames = [UIFont fontNamesForFamilyName: familyName]; for (NSString * fontName in fontNames) {printf ("\ tFont: % s \ n ", [fontName UTF8String]) ;}}

How does IOS customize UIFont fonts?

Do you mean dayoou.com? The font provided by the iOS system is limited. When customizing UIFont fonts, I usually use the following method: font files (. ttf format or. odf format) Method 1: add the corresponding font (. ttf or. odf) to resurce of the project, use the FontLabel library in cocos2d, FontLabel inherits from UILabel, just like UILabel. FontName directly uses the name of the added resource. Method 2: 1. Add the corresponding font (. ttf or. odf) to the project resurce, such as my. ttf. 2. In info. plist, add a Fonts provided by application (the value corresponding to item0 is my. ttf, and add multiple Fonts in sequence ). 3. When using aLabel. font = [UIFontfontWithName: @ "XXX" size: 30]; note that XXX is not necessarily my, here is return to castle. You can use the following methods to view familyname and fontname: NSArray * familyNames = [UIFont familyNames]; for (NSString * familyName in familyNames) {printf ("Family: % s \ n ", [familyName UTF8String]); NSArray * fontNames = [UIFont fontNamesForFamilyName: familyName]; for (NSString * fontName in fontNames) {printf ("\ tFont: % s \ n ", [fontName UTF8String]) ;}}

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.