Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

ios - 我可以在iPhone应用程序中嵌入自定义字体吗?(Can I embed a custom font in an iPhone application?)

I would like to have an app include a custom font for rendering text, load it, and then use it with standard UIKit elements like UILabel .

(我想要一个包含自定义字体的应用程序,用于呈现文本,加载文本,然后将其与UILabel等标准UIKit元素一起使用。)

Is this possible?

(这可能吗?)

  ask by Airsource Ltd translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

iOS 3.2 and later support this.

(iOS 3.2及更高版本支持此功能。)

Straight from the What's New in iPhone OS 3.2 doc:

(直接来自iPhone OS 3.2文档的新增功能 :)

Custom Font Support

(自定义字体支持)
Applications that want to use custom fonts can now include those fonts in their application bundle and register those fonts with the system by including the UIAppFonts key in their Info.plist file.

(现在,想要使用自定义字体的应用程序可以在其应用程序包中包含这些字体,并通过在其Info.plist文件中包含UIAppFonts键在系统中注册这些字体。)

The value of this key is an array of strings identifying the font files in the application's bundle.

(该键的值是一个字符串数组,用于标识应用程序捆绑包中的字体文件。)

When the system sees the key, it loads the specified fonts and makes them available to the application.

(当系统看到密钥时,它将加载指定的字体并将其提供给应用程序。)

Once the fonts have been set in the Info.plist , you can use your custom fonts as any other font in IB or programatically.

(一旦在Info.plist设置了字体,就可以将自定义字体用作IB中的其他任何字体,也可以以编程方式使用。)

There is an ongoing thread on Apple Developer Forums:

(苹果开发者论坛上有一个正在进行的话题:)
https://devforums.apple.com/thread/37824 (login required)

(https://devforums.apple.com/thread/37824 (需要登录))

And here's an excellent and simple 3 steps tutorial on how to achieve this (broken link removed)

(这是关于如何实现此目标的出色且简单的3个步骤的教程(断开的链接已删除))

  1. Add your custom font files into your project using Xcode as a resource

    (使用Xcode作为资源将自定义字体文件添加到项目中)

  2. Add a key to your Info.plist file called UIAppFonts .

    (将一个密钥添加到名为UIAppFontsInfo.plist文件中。)

  3. Make this key an array

    (将此键设为数组)

  4. For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array

    (对于每种字体,输入字体文件的全名(包括扩展名)作为UIAppFonts数组的项目)

  5. Save Info.plist

    (保存Info.plist)

  6. Now in your application you can simply call [UIFont fontWithName:@"CustomFontName" size:12] to get the custom font to use with your UILabels and UITextViews , etc…

    (现在,在您的应用程序中,您只需调用[UIFont fontWithName:@"CustomFontName" size:12]即可获得与UILabelsUITextViews等配合使用的自定义字体。)

Also: Make sure the fonts are in your Copy Bundle Resources.

(另外:确保字体在您的副本捆绑资源中。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...