Xcode使用自定义字体文件

iOS开发中系统自带的字体不能满足需求,需要自定义字体,应该怎么做呢?手把手教你使用


  • 1.拿到下载到的字体文件,拖入项目中

     

    拖入项目.png

  • 2.配置info.plist文件 配置字段"Fonts provided by application" 添加字体的item

     

    配置info.plist.png

  • 3.进入Target->Build Phases->Copy Bundle Resources. 查看是否有对应的字体,如果没有,拖入对应的字体文件

    查看setting.png

    ](http://upload-images.jianshu.io/upload_images/1054708-30790a34208a5613.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    扫描二维码关注公众号,回复: 5760049 查看本文章
  • 4.使用storyBoard设置字体

     

    在storyBoard中设置字体.png

Snip20151227_12.png

  • 5.添加下面代码遍历所有的字体文件,然后找你的字体,设置就ok
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++)
{
    NSString *fontFamily = [fontFamilies objectAtIndex:i];
    NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
    NSLog (@"%@: %@", fontFamily, fontNames);
}

 

使用代码设置字体.png

最后的效果

猜你喜欢

转载自blog.csdn.net/Lea__DongYang/article/details/83096649