-
托入iconfont资源
在https://www.iconfont.cn/中的购物车里下载代码,把里面的.ttf托入工程 -
向系统注册此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]
- 在label中使用字体
UILabel *label = ...
label.font = get the font here ...
label.text = ...
示例代码:
https://github.com/ACommonChinese/iconFont-iOS
![](https://img.haomeiwen.com/i65036/fb1c91e2900bb2a3.png)
网友评论