某些字体不显示?
我的应用程序中有一个字体名称列表,它们全部以它们代表的字体显示。但以下三个不起作用:
ArialRoundedMTBold
黑板SE-粗体
TrebuchetMS-Bold
相反,它们以标准字体显示。
有什么想法为什么这些可能不会出现吗?
I have a list of font names in my app, which are all displayed in the font they represent. The following three do not work though:
ArialRoundedMTBold
ChalkboardSE-Bold
TrebuchetMS-Bold
Instead they display in the standard font.
Any ideas why these might not be showing up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如何配置自定义字体
要使用自定义字体(iOS 中未包含的字体),您必须编辑
-Info.plist
文件并创建一个新的UIAppFonts
类型为数组的键,其中数组的每个元素都是带有字体文件名称的字符串。示例:VAGRoundedStd-Light.ttf
。您还必须将该文件添加到您的项目中。注意:当您键入
UIAppFonts
并按 Enter 键时,按键将转换为“应用程序提供的字体”。但是,当您在 Interface Builder 中(或使用
UIFont
)使用该字体时,您不会使用该字体的文件名,而是使用该字体时出现的名称。您在 Mac 的应用程序Font Book中打开该字体。对于前面的示例,它将是VAG Rounded Std Light
。OS X 比 iOS 更能容忍 TrueType 格式,因此在极少数情况下,您可能会找到适用于 OS 的字体X 但 iOS 中没有。如果发生这种情况,请更换字体,看看至少您的过程是否正确。
如何以编程方式加载字体
这解决了字体许可证要求您分发加密字体的情况。
以下秘籍来自 动态加载 iOS 字体马可·阿门特.它使字体在 UIFont 和 UIWebView 中可用。相同的代码可用于从 Internet 加载字体。
如何加载同一家族的两种以上字体
这是iOS拒绝加载同一家族的两种以上字体的情况。
以下是 stackoverflow 用户 Evadne Wu 提供的代码解决方法。只需将以下内容粘贴到您的应用程序委托中(请注意,它使用两个框架):
作为 gist 提供。在作者博客中评论: 在 iOS 上加载来自同一字体系列的 2 种以上字体。
另一种更复杂的解决方法来自 pixeldock.com:
如果您看到这种情况发生,这是您的 SDK 版本的限制,唯一的解决方法是使用 Fontforge 等字体编辑器编辑字体系列。再次,来自 pixeldock.com:
How to configure a custom font
To use a custom font (one not included in iOS) you have to edit your
<appname>-Info.plist
file and create a newUIAppFonts
key with type array, where each element of the array is a String with the name of your font file. Example:VAGRoundedStd-Light.ttf
. You also have to add the file to your project.Note: When you type
UIAppFonts
and press enter, the key is converted to "Fonts provided by application".However, when you use the font in Interface Builder (or with
UIFont
) you don't use the filename of the font, but the name that appears when you open the font in the application Font Book of your Mac. For the previous example it would beVAG Rounded Std Light
.OS X is more tolerant than iOS digesting TrueType formats, so on rare occasions you may find a font that works in OS X but not in iOS. If that happens, replace the font to see if at least you got the process right.
How to load a font programmatically
This solves the case where the font license requires you to distribute the font encrypted.
This following recipe is from Loading iOS fonts dynamically by Marco Arment. It makes the fonts available in UIFont and UIWebView. The same code can be used to load fonts from the Internet.
How to load more than two fonts of the same family
This is the case where iOS refuses to load more than two fonts from the same family.
Here is a code workaround from stackoverflow user Evadne Wu. Simply stick the following in your app delegate (note that it uses two frameworks):
Available as gist. Commented in the author blog: Loading 2+ fonts on iOS from the same font family.
An alternative, more involved workaround from pixeldock.com:
If you see this happening, it is a limitation of your SDK version, and the only way out of it is editing the font family with a Font editor like Fontforge. Again, from pixeldock.com:
iOS 中仅提供 Mac OS 字体的子集。如果您设置的字体不可用,它将显示为标准 Helvetica。
Only a subset of Mac OS fonts are available in iOS. If you set a font that is not available, it will be displayed as the standard Helvetica.
我使用的是名为 Arvo 的 Google 字体。它具有以下文件:
Arvo-Regular.ttf
Arvo-Bold.ttf
Arvo-BoldItalic.ttf
Arvo-斜体.ttf
这些名称已添加到我的应用程序的 info.plist 中,但由于某种原因,我的应用程序只能读取粗体、粗体和斜体字体。当我尝试加载它时,它无法读取常规字体。然而,打印出字体名称后,Arvo-Regular 在我的应用程序中被识别为 Arvo。
I was using a Google font named Arvo. It had the following files:
Arvo-Regular.ttf
Arvo-Bold.ttf
Arvo-BoldItalic.ttf
Arvo-Italic.ttf
These names were added into my app's info.plist but for some reason, my app could only read the bold, bolditalic, and italic fonts. It couldn't read the regular font when i tried to load it. However, after printing out the font names, it came out that Arvo-Regular was recognized as Arvo in my app.
我也遇到了类似的问题,找不到 Chalkduster - 尽管 IB 将其列为字体并且将其列为 IOS 字体。我发现 iPhone 和 iPad 上的字体列表并不相同。
Chalkduster 适用于 iPad,但不适用于 iPhone。黑板在 iPad 4.x 上可用,但在 3.x 上不可用。它可在 iPhone 3.x 和 iPhone 3.x 上使用。 4.x。
更多详细信息请参见:http:// www.whatsyourdigitaliq.com/2011/05/11/fonts-available-in-various-versions-of-ios/
I had a similar issue with not finding Chalkduster - even though IB listed it as a font and it's listed as an IOS font. I discovered that the list of fonts on iPhone and iPad is not identical.
Chalkduster is available for iPad but not iPhone. Chalkboard is available on iPad 4.x but not 3.x. It is available on iPhone 3.x & 4.x.
More details here: http://www.whatsyourdigitaliq.com/2011/05/11/fonts-available-in-various-versions-of-ios/
打开字体簿应用程序。如果您自己安装了字体,请转到用户,查找您想要的字体并在您的 xcode 项目中使用该字体的 PostScript 名称。
它甚至应该适用于同一家族的不同字体变体。
Open Font Book application. If you installed the fonts yourself, go to user, look for the fonts you want and use the PostScript name of the font in your xcode project.
It should work even for different font variations of the same family.