iOS中使用iconfont

写在前面

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

你可能感兴趣的:(iOS中使用iconfont)