摘要:点点iOS项目自己功能较多,致使应用体积也比较大。一个Xcode工程下图片资源占用了很大的空间,且若是有些App须要一键换肤功能,呵呵,不知道得作多少图片。每套图片还须要设置1x@,2x@,3x@等javascript
IconFont技术起源于Web领域的Web Font技术。随着时间的推移,网页设计愈来愈漂亮。可是电脑预装的字体远远没法知足设计者的要求,因而Web Font技术诞生了。一个英文字库并不大,经过网络下载字体,完成网页的显示。有了Web Font技术,大大提高了设计师的发挥空间。html
网页设计中图标须要适配多个分辨率,每一个图标须要占用一次网络请求。因而有人想到了用Web Font的方法来解决这两个问题,就是IconFont技术。将矢量的图标作成字体,一次网络请求就够了,能够保真缩放。解决这个问题的另外一个方式是图片拼合的Sprite图。java
Web领域使用IconFont相似的技术已经多年,当我在15年接触BootStrap的时候Font Awesome技术大行其道。最近IconFont技术在iOS图片资源方面得以应用,最近有点时间本身研究整理了一番,在此记录学习点滴。git
纯色icon
网上说了一大堆如何制做IconFont的方法,在此不作讨论。github
初步尝试使用xcode
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:@"\U0000e696 \U0000e6ab \U0000e6ac \U0000e6ae"];
[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)];
[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(3, 1)];
[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(9, 1)];
self.label.attributedText = attributedStr;
[self.view addSubview:self.label];
pragma mark - getter and setter
-(UILabel *)label{
if (!_label) {
_label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, BoundWidth-200, 40)];
_label.font = [UIFont fontWithName:@"iconfont" size:24];
_label.textColor = [UIColor purpleColor];
}
return _label;
}复制代码
利用IconFont生成1个UIImage只须要LBPIconFontmake(par1, par2, par3),par1:iconfont的unicode值;par2:图片大小;par3:图片的颜色值。网络
其中,LBPIconFontmake是一个宏,#define LBPIconFontmake(text,size,color) [[LBPFontInfo alloc] initWithText:text withSize:size andColor:color]。学习
self.latestImageView.image = [UIImage iconWithInfo:LBPIconFontmake(@"\U0000e6ac", 60, @"000066") ];复制代码