简单记录下在项目中使用自定义字体的方法。

Import

  1. 将字体文件直接拖入Xcode。可以建立独立文件夹存放:Resources/Fonts/
  2. info.plist中新建字段:Fonts provided by application
  3. item所对应的Value值中填入字体文件的名称如:TitilliumText25L.otf

Usage

  1. Storyboard中可直接使用。
  2. Launch Screen中使用还有问题,在Xcode中看见已经是自定义的字体,但是运行起来之后,却用的是System Font,应该是Xcode的一个bug。
  3. 代码中使用,注意是用font name而不是font family name
myLabel.font = [UIFont fontWithName:@"TitilliumText25L-999wt" size:14];

Available Fonts

for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);
        
    for (NSString* name in [UIFont fontNamesForFamilyName: family])
  {
	NSLog(@"  %@", name);
  }
}

Reference

CODEwithChris