我们如何在 iOS 应用中使用自定义字体?

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

How can we use custom font in an iOS app?

iphoneiosfonts

提问by Dev

Possible Duplicate:
Can I embed a custom font in an iPhone application?

可能的重复:
我可以在 iPhone 应用程序中嵌入自定义字体吗?

How can I customize font in my iPhone app? Is it possible? How can I use this custom font in a UILabel?

如何在我的 iPhone 应用程序中自定义字体?是否可以?如何在UILabel.

I am trying to add MYRIADPRO-SEMIBOLD.OTFfont in my App.

我正在尝试MYRIADPRO-SEMIBOLD.OTF在我的应用程序中添加字体。

and the code is

代码是

UIFont *customFont = [UIFont fontWithName:@"MYRIADPRO-SEMIBOLD" size:35]; 
titleLbl.font = customFont; 

And the Plist is

而 Plist 是

enter image description here

在此处输入图片说明

回答by Kamar Shad

Try the steps below:

请尝试以下步骤:

1. Make configuration in the info.plist as shown in Image

1. 在 info.plist 中进行配置,如图

enter image description here

在此处输入图片说明

2. Now you should use that added file

2. 现在你应该使用添加的文件

UIFont *customFont = [UIFont fontWithName:@"fontName" size:size];

// further you may set That Font to any Label etc.

EDIT:Make Sure you have added that file in your resources Bundle.

编辑:确保您已将该文件添加到您的资源包中。

enter image description here

在此处输入图片说明

回答by edzio27

  1. Copy your font file into Resources.

  2. In your application .plist create (if it exists just create a row) a row called Fonts provided by applicationand then in item 0copy your font name for example Ciutadella-Bold.otf

  3. Then you can define this font in your application:

    UIFont *CiutadellaBold = [UIFont fontWithName:@"Ciutadella-Bold" size:17.0f];
    
  4. And use it in for instance in UILabel:

    [uiLabel setFont:CiutadellaBold];
    
  1. 将您的字体文件复制到资源中。

  2. 在您的应用程序 .plist 中创建(如果它存在,则创建一行)名为的行Fonts provided by application,然后item 0复制您的字体名称,例如Ciutadella-Bold.otf

  3. 然后你可以在你的应用程序中定义这个字体:

    UIFont *CiutadellaBold = [UIFont fontWithName:@"Ciutadella-Bold" size:17.0f];
    
  4. 并将其用于例如UILabel

    [uiLabel setFont:CiutadellaBold];