IOS自定义控件
来源:互联网 发布:java采购管理系统 编辑:程序博客网 时间:2024/06/05 07:36
前段时间,公司在开发软件时。为了节省开发成本,就把美工切图这一块去掉了。为此~~,个人对这一块是非常的头疼。但不幸中的万幸是,从中学到点东西。首先就是矢量图标。有兴趣的可以看看阿里的:http://www.iconfont.cn。原理就是把项目中要用到的图片转化为特殊字体。在项目中以label的形式展示出来。听到这里是不是感觉还不错。
要想用iconfont需要配置环境 可以参照阿里的配置文档:http://www.iconfont.cn/help/iconuse.html
1、将您IconFont刚下载的字体文件(.ttf)添加到工程中;
2、打开Info.plist文件,增加一个新的Array类型的键,键名设置为UIAppFonts(Fonts provided by application),增加字体的文件名:“iconfont.ttf“
使用IconFont字体:
UILabel * label = [[UILabel alloc] initWithFrame:self.view.bounds];
UIFont *iconfont = [UIFont fontWithName:@"uxIconFont" size: 34];//这里需要注意下,@“”里面的类型需要与倒入工程ttf的类型一致。
label.font = iconfont;
label.text = @"\U00003439 \U000035ad \U000035ae \U000035af \U000035eb \U000035ec";
[self.view addSubview: label];
但是在工程中使用时又有点缺憾,就是当我为的按钮需要用到icon font时回很麻烦,无奈只能用自定义控件。
自定义button的.h文件
@property(nonatomic,strong)UILabel * IconLabel;
@property(nonatomic,assign)float PX;
.m中的实现
-(void)drawRect:(CGRect)rect
{
CGRect rect1=[[UIScreen mainScreen] bounds];
CGSize size=rect1.size;
CGFloat WIDTH=size.width;
UIFont *iconfont=nil;
_IconLabel=[[UILabel alloc]initWithFrame:self.bounds];
_IconLabel.textAlignment=NSTextAlignmentCenter;
if (WIDTH==320)
{
iconfont = [UIFont fontWithName:@"IconFont" size: _PX];
}
else if (WIDTH==375)
{
iconfont = [UIFont fontWithName:@"IconFont" size: _PX+2];
}
else if (WIDTH==414)
{
iconfont = [UIFont fontWithName:@"IconFont" size: _PX+4];
}
self.IconLabel.font=iconfont;
self.IconLabel.text=self.titleLabel.text;
[self addSubview:self.IconLabel];
}
在调用的时候只需要倒入头文件实现就行
_OrderStatusBtn=[[KCButtonalloc]initWithFrame:CGRectMake(WIDTH1*230/320, MarginY, WIDTH1*80/320, CarHeight)];
_OrderStatusBtn.backgroundColor=CustomColor(61,216,76, 1);
_OrderStatusBtn.layer.borderColor =CustomColor(61,216,76, 1).CGColor;
_OrderStatusBtn.layer.borderWidth =1;
_OrderStatusBtn.layer.cornerRadius =6;
_OrderStatusBtn.layer.masksToBounds =YES;
_OrderStatusBtn.PX=12;
_OrderStatusBtn.titleLabel.textColor=[UIColorwhiteColor];
[selfaddSubview:_OrderStatusBtn];
- ios中自定义控件
- 自定义ios控件介绍
- ios自定义星级控件
- 自定义iOS控件
- 自定义ios控件介绍
- ios 自定义控件 方法
- IOS自定义UI控件
- IOS开发--自定义控件
- IOS开发--自定义控件
- IOS自定义控件注意
- iOS自定义控件
- iOS自定义控件_CustomTextView
- 自定义iOS控件
- iOS--自定义系统控件
- IOS自定义控件
- iOS自定义日历控件
- iOS自定义控件一
- iOS自定义控件二
- ZOJ-3930-Dice Notation
- Hackgame2攻略
- 忙死了!跨境电商CEO自述
- 启程Android之路
- C++游戏系列4:杀伤距离有限制
- IOS自定义控件
- CentOS 7 安装 Hadoop2.7.1
- ocx工程及不显示椭圆的方法
- 第七周项目二-友元类
- 【Petuum 源码解析】之K-Means分布式算法源码
- python中的reduce函数
- Direct2D Intro - Clip a Bitmap Source
- 聚合数据API用法简介
- CAS配置二-通过数据库进行登录验证