自定制ProgressView
来源:互联网 发布:大数据概念板块 编辑:程序博客网 时间:2024/05/18 22:53
苹果原生的progressView高度不可变,用起来很是不方便,说不定以后用的到,别人说不定也用的到,还是自己写一个。
下边是主要的代码,详细的代码可以参考https://github.com/gofey/LittleDemos自定义ProgressView这一项
闲话不说,都是比较基础的代码,都能看得懂
我是自定制的一个View
重新initWithFrame方法
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [superinitWithFrame:frame]) {
//初始化
UIImageView *trackView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, frame.size.width, frame.size.height)];
[selfaddSubview:trackView];
self.trackView = trackView;
trackView.clipsToBounds =YES;
self.layer.cornerRadius = frame.size.height / 2;
UIImageView *progressView = [[UIImageViewalloc]initWithFrame:CGRectMake(1,3, frame.size.width -2, frame.size.height -6)];
[selfaddSubview:progressView];
//记录原始总宽度,计算进度时候使用
_wholeWidth = progressView.width;
self.progressView = progressView;
progressView.clipsToBounds =YES;
progressView.layer.cornerRadius = progressView.height /2;
UIImageView *progressRightView = [[UIImageViewalloc]initWithFrame:CGRectMake(progressView.x -33, (frame.size.height -32) /2,33,32)];
[selfaddSubview:progressRightView];
self.progressRightView = progressRightView;
progressRightView.hidden =YES;
UIImageView *progressDataImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,45,30)];
[selfaddSubview:progressDataImageView];
self.progressDataImageView = progressDataImageView;
progressDataImageView.hidden =YES;
UILabel *dataLabel = [[UILabelalloc]initWithFrame:progressDataImageView.bounds];
[progressDataImageViewaddSubview:dataLabel];
self.dataLabel = dataLabel;
dataLabel.textColor = [UIColorwhiteColor];
dataLabel.font = [UIFontsystemFontOfSize:17];
dataLabel.textAlignment =NSTextAlignmentCenter;
}
returnself;
}
修改进度方法
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated{
_progress = progress;
self.dataLabel.text = [NSStringstringWithFormat:@"%.0f",_dataTatal * progress];
if (animated) {
[UIViewanimateWithDuration:0.3animations:^{
[selfchageFrame];
} completion:^(BOOL finished) {
}];
}else{
[selfchageFrame];
}
}
//改变Frame
- (void)chageFrame{
//调整进度View的frame
self.progressView.frame =CGRectMake(_progressView.x,_progressView.y,_wholeWidth * _progress,_progressView.height);
//调整右边光view的frame
self.progressRightView.frame =CGRectMake(CGRectGetMaxX(self.progressView.frame) - 50, _progressRightView.y,_progressRightView.width,_progressRightView.height);
//调整上部显示数据view的frame
self.progressDataImageView.frame =CGRectMake(CGRectGetMaxX(self.progressView.frame), - _progressDataImageView.height -5,_progressDataImageView.width,_progressDataImageView.height);
self.dataLabel.text = [NSStringstringWithFormat:@"%.0f",self.dataTatal *_progress];
}
改变progress的时候,不需要动画就调用以上方法,animated值为NO,需要动画为Yes.
- 自定制ProgressView
- progressview
- 自定制linux系统
- 自定制网页对话框
- ICMP 报文自定制
- 自定制模版
- 自定制代码段
- 自定制Application类
- wince 拨号界面自定制
- 使用自定制的dll
- Struts自定制结果类型
- Jquery easyUI 自定制图标
- Hadoop的自定制数据类型
- 自定制vim编辑器属性
- 【Android系统】自定制View
- iOS 自定制弹框
- 自定制视频播放器
- UI组件:ProgressView进度条
- 谈谈对Spring IOC的理解
- 管理器点击浏览时出现Service Unavailable
- C++第四次实验-函数-项目2(奇偶阶乘)
- Circular Queue
- R语言中的机器学习
- 自定制ProgressView
- 如何把字符串转换成整数
- volatile关键字详解
- MyBatis拦截器分页原理及PageHelper分页插件教学
- jni异常,c++抛出异常,java捕获
- numpy 中的ndarray数组返回符合特定条件的索引方法
- 【转】UsbAccessory和UsbDevice的区别
- unity MeshCollider组件
- 扎心了!论虐狗我只服UI设计师!