如何在iOS 7中使用自定义字体"Montserrat"?

3

我正在开发一个应用程序,需要在应用中使用自定义字体 Montserrat。请问有谁能帮我解决这个问题?

Font Family Name : Montserrat

可能是Can I embed a custom font in an iPhone application?的重复问题。 - The dude
1
https://dev59.com/T2cs5IYBdhLWcg3wOBbl - The dude
1
https://dev59.com/eG865IYBdhLWcg3wZNrT?lq=1 - The dude
@Thedude 我已经做了所有这些事情,但是在Nslog中却得到了(null)。 - Ganesh Kumar
如果你在提问中陈述了你为了达到目标所尝试过的方法以及遇到的问题,那么请在问题中说明。请参考帮助部分并查看如何提出一个好问题:http://stackoverflow.com/help/how-to-ask - The dude
2个回答

3

将自定义字体族和样式拖放到您的项目中。

在您的应用程序-->info.plist中,您应该添加以下内容

enter image description here

之后,我们可以轻松地在Interface Builder -> Show the Attribute Inspector中检查字体族。

enter image description here

编程方式

UIFont* font = [UIFont fontWithName:@"Montserrat" size:20];

您可以通过将以下代码添加到您的项目中来检查字体文件是否已添加。

for (NSString *fontFamilyName in [UIFont familyNames]) 
{
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName]) 
{
    NSLog(@"Family: %@    Font: %@", fontFamilyName, fontName);
}
}

2
  1. 如果您想在Storyboard上应用字体,请使用IBCustomFonts

  2. 对UIFont类进行分类,以便在需要更改的任何地方应用此字体。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接