寫在前面
iconfont技術(shù)是將圖標(biāo)(icon)轉(zhuǎn)換為字體(font)箕肃,在iOS開發(fā)中可以減少App的體積刃唤。這里以阿里巴巴的iconfont為例冬骚。
iconfont的使用
- 在iconfont網(wǎng)站選中需要的圖標(biāo)嘶窄,下載代碼糖赔,解壓縮文件包
-
在Xcode工程中添加ttf字符集imageimage
-
在plist文件中添加相應(yīng)字段image
-
通過文件包中的html文件查看圖標(biāo)的Unicode編碼image
- 添加label
//初始化label
UILabel *iconfontLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 100, 200, 200)];
//字體設(shè)置為iconfont
iconfontLabel.font = [UIFont fontWithName:@"iconfont" size:50];
//添加Unicode編碼战虏,格式為\U0000 + 圖標(biāo)的Unicode編碼
iconfontLabel.text = @"\U0000e64e";
//顯示label
[self.view addSubview:iconfontLabel];
-
添加圖標(biāo)成功image