How to embed a font in an iPad application-non-person cloud Edition

Source: Internet
Author: User

Today, we are doing technical verification for the 21 st Century Newspaper's iPad app, trying to add fonts not available for the iPad to the app. Google first. The solution is simple. iOS 3.2 and above support embedded user fonts. There are many blog articles or forum posts about this technology, and there are also Chinese posts. However, there are almost all Chinese articles or posts. I guess most of these honorable authors have not verified them by themselves, or are unwilling to share their problems and solutions after verification.

 

Go to the topic. The built-in font method is supported in IOS 3.2 and later versions. There are three steps:

 

1. Add the font file to the resources file group of the project (do not say you won't );

2. Add the uiappfonts item (array type) to the info. plist file of the project, and write the font file name as an element;

3. reference the font in the project code, for example, label. font = [uifont fontwithname: @ "name" Size: 14.0f].

 

Simple? Very simple. However, if you try to embed a Chinese font (for example, "文" in MAC), you may encounter problems. You have correctly placed the font in the resources file group and entered info correctly. plist file, and, label. font = [uifont fontwithname: @ "文" Size: 14.0f] No error is reported. Good, build and go! What's going on? The label text is not the imitation style as you wish, or the default Georgia font.

 

That's why most Chinese authors do not personally validate the software-or do they only develop English software? If you are not familiar with the concepts related to fonts, it is too normal to encounter this problem. To put it bluntly, we must use the font in the third step.Family Name)Instead of fontFile Name!

 

So what is the real name of "文? You do not need to rely on the search engine. You can find the following three lines of code:

 

For (nsstring * fontname in [uifont familynames]) {<br/> nslog (@ "% @", fontname); <br/>} 

 

In the debugger Console window, you will see a lot of fonts supported by the iPad system:

 

 

[Session started at 18:06:05 + 0800.]

18:06:06. 211 bunddlefonttest [4537: 207] Bodoni Ornaments

18:06:06. 213 bunddlefonttest [4537: 207] applegothic

18:06:06. 214 bunddlefonttest [4537: 207] Gill sans

18:06:06. 214 bunddlefonttest [4537: 207] hiragino Kaku Gothic pron

18:06:06. 217 bunddlefonttest [4537: 207] palatino

18:06:06. 218 bunddlefonttest [4537: 207] Copperplate

18:06:06. 219 bunddlefonttest [4537: 207] Bodoni 72 smallcaps

18:06:06. 220 bunddlefonttest [4537: 207] Bradley hand

18:06:06. 221 bunddlefonttest [4537: 207] heiti K

18:06:06. 222 bunddlefonttest [4537: 207] db LCD temp

18:06:06. 222 bunddlefonttest [4537: 207] Helvetica

18:06:06. 223 bunddlefonttest [4537: 207] marker felt

18:06:06. 223 bunddlefonttest [4537: 207] Times New Roman

18:06:06. 224 bunddlefonttest [4537: 207] verdana

18:06:06. 224 bunddlefonttest [4537: 207] hiragino mincho pron

18:06:06. 225 bunddlefonttest [4537: 207] zapl dingbats

18:06:06. 225 bunddlefonttest [4537: 207] Georgia

18:06:06. 225 bunddlefonttest [4537: 207] Arial rounded Mt bold

18:06:06. 226 bunddlefonttest [4537: 207] papyrus

18:06:06. 226 bunddlefonttest [4537: 207] trebuchet MS

18:06:06. 227 bunddlefonttest [4537: 207] Baskerville

18:06:06. 227 bunddlefonttest [4537: 207] stfangsong

18:06:06. 228 bunddlefonttest [4537: 207] heiti TC

18:06:06. 228 bunddlefonttest [4537: 207] geeza pro

18:06:06. 229 bunddlefonttest [4537: 207] Bodoni 72

18:06:06. 229 bunddlefonttest [4537: 207] courier

18:06:06. 229 bunddlefonttest [4537: 207] running in

18:06:06. 230 bunddlefonttest [4537: 207] heiti J

18:06:06. 230 bunddlefonttest [4537: 207] Arial

18:06:06. 231 bunddlefonttest [4537: 207] Arial Hebrew

18:06:06. 232 bunddlefonttest [4537: 207] Courier New

18:06:06. 232 bunddlefonttest [4537: 207] zapfino

18:06:06. 232 bunddlefonttest [4537: 207] Academy engraved let

18:06:06. 233 bunddlefonttest [4537: 207] chalkduster

>
>18:06:06. 233 bunddlefonttest [4537: 207] Bodoni 72 oldstyle

18:06:06. 233 bunddlefonttest [4537: 207] hoefler text

18:06:06. 234 bunddlefonttest [4537: 207] Futura

18:06:06. 234 bunddlefonttest [4537: 207] Snell roundhand

18:06:06. 235 bunddlefonttest [4537: 207] American typewriter

18:06:06. 235 bunddlefonttest [4537: 207] heiti SC

18:06:06. 236 bunddlefonttest [4537: 207] optima

18:06:06. 237 bunddlefonttest [4537: 207] Helvetica Neue

18:06:06. 238 bunddlefonttest [4537: 207] Comic Sans MS

18:06:06. 239 bunddlefonttest [4537: 207] Party let

18:06:06. 240 bunddlefonttest [4537: 207] thonburi

18:06:06. 241 bunddlefonttest [4537: 207] didot

 

The built-in "文" is also included, but it is changed to "stfangsong ". That's right. This is the family name of the Chinese Imitation Song Dynasty and the font name that should be used in the code. Change the code:

 

 

 

Labelchinese. font = [uifont fontwithname: @ "stfangsong" Size: 43.0f];

Labelchinese. Text = @ "test ";

 

The running effect is as follows (I also added the English font Comic Sans MS ):

 

 

 

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.