iconfont for iOS

  1. 托入iconfont资源
    在https://www.iconfont.cn/中的购物车里下载代码,把里面的.ttf托入工程

  2. 向系统注册此ttf

NSURL *fontFileUrl = [[NSBundle mainBundle] URLForResource:@“yourResourceName” withExtension:@"ttf"];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)url);
CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
CTFontManagerRegisterGraphicsFont(newFont, NULL);
CGFontRelease(newFont);

// 注册后可以获取字体(注册只需要一次)
[UIFont fontWithName:name size:size]
  1. 在label中使用字体
 UILabel *label = ...
 label.font = get the font here ...
 label.text = ...

示例代码:

https://github.com/ACommonChinese/iconFont-iOS

iconfont for iOS_第1张图片
Simulator Screen Shot - iPhone 8 - 2019-03-05 at 11.47.11.png

你可能感兴趣的:(iconfont for iOS)