2012-10-23 197 views
21

可能重复:
Can I embed a custom font in an iPhone application?自定义字体

我怎么可以自定义字体在我的iPhone应用程序? 这可能吗? 如何为标签提供此自定义字体? 任何人都可以提出一个好方法吗?

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

而且代码

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

而且plist中是

enter image description here

回答

67

请尝试以下步骤。如图形象的info.plist

1进行配置

enter image description here

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

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

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

编辑:请确保您有在你的资源包中添加该文件。 enter image description here

+0

它不是为我工作:( – Dev

+0

@Dev你应该通过从要使用Font.and看到我edit.Make确保您有补充说,该文件的名称文件在你的资源包。 – Kamarshad

+2

@Dev这是解决方案,它的工作原理是确保你将字体文件添加到资源文件夹中,并且当你在源代码中设置字体时,使用:(例如,如果你想使用bolda.ttf)[UIFont fontWithName @ “bolda”size:15];(不要添加.ttf) – Ashbay

5
  1. 复制你的字体文件导入Resources

  2. 在您的应用程序.plist中创建一个名为“应用程序提供的字体”的行,然后在“项目0”中复制您的字体名称,例如“Ciutadella-Bold”。 OTF”

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

    UIFont *CiutadellaBold = [UIFont fontWithName:@"Ciutadella-Bold" size:17.0f]; 
    
  4. 而且在使用的UILabel在例如:

    [uiLabel setFont:CiutadellaBold];