xcode 如何在 iOS 应用中使用自定义字体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9351264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use custom font in iOS Apps?
提问by Fire Fist
Possible Duplicate:
Can I embed a custom font in an iPhone application?
Hi I would like to use myanmar font in my native iOS Apps.
嗨,我想在我的原生 iOS 应用程序中使用缅甸字体。
However i don't know how to use that font.
但是我不知道如何使用该字体。
Font name is Zawgyi.ttf and It's myanmar font.
字体名称是 Zawgyi.ttf,是缅甸字体。
I already installed that font in my macbook and i didn't found that font in my xcode project's font property.
我已经在我的 macbook 中安装了该字体,但在我的 xcode 项目的字体属性中没有找到该字体。
I'm just beginner for iOS.
我只是 iOS 的初学者。
Please guide me how to do that?
请指导我如何做到这一点?
Thanks you for reading.
感谢您的阅读。
回答by Saurabh
You just need to drag the font's ttf file in your resource folder and do this following entry in your info.plist file –
你只需要在你的资源文件夹中拖动字体的 ttf 文件,然后在 info.plist 文件中执行以下条目 -
<key>UIAppFonts</key>
<array>
<string>CloisterBlack.ttf</string>
</array>
UIAppFonts key accept a array so you can pass multiple fonts in it.
UIAppFonts 键接受一个数组,以便您可以在其中传递多种字体。
Now wherever you want to use the font in your application you can call:
现在,无论您想在应用程序中使用字体的任何位置,都可以调用:
[UIFont fontWithName:@"Cloister Black" size:64.0]
Just make sure you give the real font name in above code. The font file name and its “real font name” can be different, so just open the font in FontBook app and there you can see the real name of the font.
只要确保你在上面的代码中给出了真实的字体名称。字体文件名和它的“真实字体名称”可以不同,所以只需在FontBook应用程序中打开字体即可看到字体的真实名称。
See my blog post on same topic here - http://www.makebetterthings.com/iphone/how-to-use-custom-fonts-in-iphone/
在这里查看我关于同一主题的博客文章 - http://www.makebetterthings.com/iphone/how-to-use-custom-fonts-in-iphone/
回答by Ashraf
What about the following
下面呢
UIFont *font = [UIFont fontWithName:@"Zawgyi" size:20];
[label setFont:font];