iOS iconfont设置

来源:互联网 发布:倒卖车辆数据 编辑:程序博客网 时间:2024/06/05 02:38

先去http://www.iconfont.cn 阿里巴巴IconFoint下载你需要的图片 点击库 里面有一个代码下载点击下载

 然后把iconfont.ttf放在工程里

 在使用的时候需要配置字体名字,然后将对应图标的Unicode编码赋给text即可进行展示,对应图标的Unicode编码在字体下载中的html文件中查看 

把这些文件添加到工程里

在.pch文件中导入头文件

#import "TBCityIconFont.h"

#import "UIImage+TBCityIconFont.h"

然后在viewController里就可以使用iconFont了

#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UILabel *label;@property (weak, nonatomic) IBOutlet UIButton *button;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];       UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];    [self.view addSubview:imageView];    imageView.image=[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e63c", 100, [UIColor redColor])];            /*---------------------label------------------------------------------------*/    //需要配置为对应的字体   self.label.font = [UIFont fontWithName:@"iconfont" size:30];//字体的名字一定要是iconfont    //配置上两个对应图标    /*图片和文字不在同一行     self.label.text = @" hahha\n \U0000e620";     self.label.numberOfLines=0;     */    //在同一行    self.label.text = @" hahha \U0000e620";    //配置图标颜色    [self.label setTextColor:[UIColor cyanColor]];        /*---------------------label------------------------------------------------*/               /*---------------------button------------------------------------------------*/        /*图片和文字在同一行 图片和文字分开设置     [self.button setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e637", 30, [UIColor yellowColor])] forState:UIControlStateNormal];     [self.button setTitle:@"哈哈" forState:UIControlStateNormal];         图片和文字在同一行 图片和文字一块设置    [self.button setTitle:@"哈哈 \U0000e637" forState:UIControlStateNormal];     self.button.titleLabel.font=[UIFont fontWithName:@"iconfont" size:19];          */         //图片和文字不在同一行 图片和文字一块设置    [self.button setTitle:@"\U0000e637 \n 哈哈" forState:UIControlStateNormal];//这样设置图片和          文字会里的有点近可以通过设置行间距 或者多加一个\n 调整图片和文字的间距    self.button.titleLabel.numberOfLines=0;    self.button.titleLabel.textAlignment=NSTextAlignmentCenter;    self.button.titleLabel.font=[UIFont fontWithName:@"iconfont" size:19];    [self.button setTintColor:[UIColor greenColor]];    /*---------------------button------------------------------------------------*/}