ios 如何在 iPhone SDK 中使用自定义字体?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14376941/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:53:50  来源:igfitidea点击:

How to use custom fonts in iPhone SDK?

iphoneiosobjective-cxcode4.2

提问by Patel Manthan

I Want to implement custom font in my app. So i have added that in my Project Source code. I don't want to set that programatically. Is this possible that I can do this with setting properties in xib?

我想在我的应用程序中实现自定义字体。所以我在我的项目源代码中添加了它。我不想以编程方式设置。我可以通过在 xib 中设置属性来做到这一点吗?

回答by Rajneesh071

  1. Addyour custom font into your project , i.e. Dragged the font file(CALIBRIZ_0.TTF) into XCode project.

  2. Edit Info.plist: Add a new entry with the key "Fonts provided by application".

  3. For each of your files, add the file name to this array

    enter image description here

  4. Opened the font in font book(double click on your font in finder) to see what the real filename is and I see this:

  1. 您的自定义字体添加到您的项目中,即将字体文件(CALIBRIZ_0.TTF)拖入 XCode 项目。

  2. 编辑 Info.plist:添加一个带有“应用程序提供的字体”键的新条目。

  3. 对于您的每个文件,将文件名添加到此数组中

    在此处输入图片说明

  4. 打开字体簿中的字体(在 finder 中双击您的字体)以查看真实文件名是什么,我看到了:

enter image description here

在此处输入图片说明

Now set font to your label

现在将字体设置为您的标签

yourLabel.font = [UIFont fontWithName:@"Calibri" size:15];

Follow thisto get more

关注获取更多

回答by Piyush Dubey

I think you had not searched well.

我认为你没有很好地搜索。

How to add CUSTOM fonts:-
Steps:-
  1.  Add your custom font files into your project using XCode as a resource
  2.  Add a key to your info.plist file called "Fonts provided by application".
  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 theUIAppFonts array
  5.  Save info.plist
  6.  Now call UIFont *fontCustom = [UIFont fontWithName:@"CustomFontName" size:12];  to get the custom fonts.
How to add CUSTOM fonts:-
Steps:-
  1.  Add your custom font files into your project using XCode as a resource
  2.  Add a key to your info.plist file called "Fonts provided by application".
  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 theUIAppFonts array
  5.  Save info.plist
  6.  Now call UIFont *fontCustom = [UIFont fontWithName:@"CustomFontName" size:12];  to get the custom fonts.

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

注意:-确保字体在您的复制包资源中。

For example:- If you want to use "Nexa Light" font in your app, then add "Nexa Light.otf" into your project and call in this way.

例如:- 如果您想Nexa Light在您的应用程序中使用“ ”字体,则将“Nexa Light.otf”添加到您的项目中并以这种方式调用。

UIFont *fontCustom = [UIFont fontWithName:@"Nexa Light" size:14];
lblName.font = fontCustom;

回答by SachinVsSachin

Step 1:
Copy the font file to your resource files. Make sure it is added to Copy Bundle Resources in your Build Phases settings.

第 1 步:
将字体文件复制到您的资源文件中。确保它已添加到您的构建阶段设置中的复制捆绑资源。

Step 2:
In your Info.plist just configure this like below this screen

第 2 步:
在您的 Info.plist 中,只需在此屏幕下方进行配置

enter image description here

在此处输入图片说明

Step 3:

第 3 步:

Access and use it with the following code:

使用以下代码访问和使用它:

UIFont *font = [UIFont fontWithName:@"YOUR_FONT" size:10];

回答by iPatel

Use font name from .ttffile

使用.ttf文件中的字体名称

and you can also find from this link

你也可以从这个链接找到

after add this font name with it's extension like (OpenScan.ttf)in to .plistfile

将此字体名称及其扩展名(OpenScan.ttf))添加.plist文件中后

enter image description here

在此处输入图片说明

After add this font to .plistfile, you can use it by

将此字体添加到.plist文件后,您可以通过

[self.txtField setFont: [UIFont fontWithName:@"OpenSans" size:13]];

And for more information read my Answer Adding custom fonts to iOS app finding their real names.

有关更多信息,请阅读我的答案将自定义字体添加到 iOS 应用程序以查找其真实姓名