IOS Add custom Font method detailed _ios

Source: Internet
Author: User

1: Get the font file

Download font files from a variety of sources TTF, website or from other IPA. (Take Fzltxh.ttf as an example)

2: Copy the Fzltxh.ttf file to the project

3: Add items to Info.plist:

Fonts provided by Application (uiappfonts) can add one or more item,

such as ITEM0--Fzltxh.ttf

4: Find the Real font name:

Because using fonts, you use the real name of the font instead of the filename, you can use the following code to traverse the font name available for the current device.

and find out the real name of the font you just added.

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]);

}

Fzltxhk--gbk1-0 This is the real use name for this font.

5: Using Fonts

[Uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];

6: Uniform replacement

If you want to replace the old project font as a whole, and do not want to change the existing code, you can rewrite

Systemfontofsize method.

#import

@interfaceUIFont (tjcustom)

+ (Uifont *) Systemfontofsize: (cgfloat) fontsize;

@end

#import "Uifont+custom.h"

@implementationUIFont (Tjcustom)

+ (Uifont *) Systemfontofsize: (cgfloat) fontsize

{

return[uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];

}

@end

In this case, originally written

The Systemfontofsize method replaces the new method, thus achieving the overall substitution effect.

Text/Left hand (Jane book author)
Original link: http://www.jianshu.com/p/edf51b8b6479
Copyright belongs to the author, reproduced please contact the author to obtain authorization, and labeled "Jane book author."

Above is the iOS adds the custom font method The data collation, the follow-up continues to supplement the related information, thanks everybody to this website support!

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.