Use custom ttf font and iOS custom ttf font on ios

Source: Internet
Author: User

Use custom ttf font and iOS custom ttf font on ios


If you want to use a third-party font in the project, you can query the solution on stackoverflow and try to add it. The example is as follows:


1. Add the xx. ttf Library to the project.

2. Add a new line of Fonts provided by application in the xx-Info.plist file of the project, with the name of the Library




3. reference the name of the library. Set the font to [UIFontfontWithName: @ "fontname" size: 24].


UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (10,100,300, 50)]; label. text = @ "this is a TEST. 123456 "; UIFont * font = [UIFont fontWithName: @" winding CS medium capacity "size: 24]; label. font = font; [self. view addSubview: label];


If you do not know the font name, you can traverse the font for query:

  for(NSString *fontfamilyname in [UIFont familyNames])    {        NSLog(@"family:'%@'",fontfamilyname);        for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])        {            NSLog(@"\tfont:'%@'",fontName);        }        NSLog(@"-------------");    }




Example Demo: http://download.csdn.net/detail/duxinfeng2010/7639683


Reference http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project




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 to customize UIFont Fonts

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.

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.