iOS中使用iconfont

2018-06-02  本文已影响0人  怀念与憧憬

写在前面

iconfont技术是将图标(icon)转换为字体(font),在iOS开发中可以减少App的体积。这里以阿里巴巴的iconfont为例。

iconfont的使用

  1. 在iconfont网站选中需要的图标,下载代码,解压缩文件包
  2. 在Xcode工程中添加ttf字符集 image image
  3. 在plist文件中添加相应字段 image
  4. 通过文件包中的html文件查看图标的Unicode编码 image
  5. 添加label
    //初始化label
    UILabel *iconfontLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 100, 200, 200)];
    //字体设置为iconfont
    iconfontLabel.font = [UIFont fontWithName:@"iconfont" size:50];
    //添加Unicode编码,格式为\U0000 + 图标的Unicode编码
    iconfontLabel.text = @"\U0000e64e";
    //显示label
    [self.view addSubview:iconfontLabel];
  1. 添加图标成功 image
上一篇 下一篇

猜你喜欢

热点阅读