自定义UIProgressView

自定义CustomporgressView
#import <UIKit/UIKit.h> @interface CustomporgressView : UIView
@property(nonatomic,assign)int step;
//allCount一共几个节点 step当前节点
-(instancetype)initWithFrame:(CGRect)frame withCount:(int)allCount withCurrentStep:(int)step;
@end
#import "CustomporgressView.h" #define TintColor [UIColor redColor]
#define TrackTintColor [UIColor lightGrayColor]
@interface CustomporgressView()
//进度条
@property(nonatomic,strong)UIProgressView *progressView;
//当前指示器
@property(nonatomic,strong)UILabel *indicatorLabel;
//圆点数组
@property(nonatomic,strong)NSMutableArray *mCircleArr; @end @implementation CustomporgressView -(instancetype)initWithFrame:(CGRect)frame withCount:(int)allCount withCurrentStep:(int)step{
self = [super initWithFrame:frame];
if(self){
self.progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width*0.8, 0)];
self.progressView.center = self.center;
self.progressView.progressTintColor = TintColor;
self.progressView.trackTintColor = TrackTintColor;
[self addSubview:self.progressView]; self.mCircleArr = [NSMutableArray array];
float width = self.progressView.frame.size.width/(allCount-1);
for(int i=0;i<allCount;i++){
UIView *circleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 12)];
circleView.center = CGPointMake(i * width,0);
circleView.clipsToBounds = YES;
circleView.layer.cornerRadius = 6.0f; [self.progressView addSubview:circleView];
[self.mCircleArr addObject:circleView];
}
[self.progressView addSubview:self.indicatorLabel];
self.step = step;
}
return self;
}
-(UILabel *)indicatorLabel{
if(!_indicatorLabel){
_indicatorLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
_indicatorLabel.textAlignment = NSTextAlignmentCenter;
_indicatorLabel.textColor = TintColor;
_indicatorLabel.layer.borderWidth = 1.0f;
_indicatorLabel.layer.cornerRadius = 12;
_indicatorLabel.layer.borderColor = TintColor.CGColor;
_indicatorLabel.backgroundColor = [UIColor whiteColor];
}
return _indicatorLabel;
} -(void)setStep:(int)step{
//超过数组边界
if(step >= self.mCircleArr.count){
return;
}
_step = step; for(int i=0;i<self.mCircleArr.count;i++){
UIView *circleView = self.mCircleArr[i];
if(i < step){
circleView.backgroundColor = TintColor;
}else{
circleView.backgroundColor = TrackTintColor;
}
} float width = self.progressView.frame.size.width/(self.mCircleArr.count-1);
self.indicatorLabel.center = CGPointMake(width * step, 0);
[ self.progressView setProgress:step*1.0/(self.mCircleArr.count-1)];
_indicatorLabel.text = [NSString stringWithFormat:@"%d",step+1]; } @end
使用:
CustomporgressView *customProgress = [[CustomporgressView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width-10, 50) withCount:5 withCurrentStep:2];
[view addSubview:customProgress];
自定义UIProgressView的更多相关文章
- Xamarin UIProgressView自定义
Progress.ProgressImage = UIImage.FromFile ("progress.png"); Progress.TrackImage = UIImage. ...
- UIProgressView 详解
自定义progressView 包括背景图片和进度条的图片以及进度条的高度. //进度条 UIProgressView *aProgressView = [[UIProgressView allo ...
- 关于Unity3D自定义编辑器的学习
被人物编辑器折腾了一个月,最终还是交了点成品上去(还要很多优化都还么做). 刚接手这项工作时觉得没概念,没想法,不知道.后来就去看<<Unity5.X从入门到精通>>中有关于 ...
- 一起学微软Power BI系列-使用技巧(5)自定义PowerBI时间日期表
1.日期函数表作用 经常使用Excel或者PowerBI,Power Pivot做报表,时间日期是一个重要的纬度,加上做一些钻取,时间日期函数表不可避免.所以今天就给大家分享一个自定义的做日期表的方法 ...
- JavaScript自定义浏览器滚动条兼容IE、 火狐和chrome
今天为大家分享一下我自己制作的浏览器滚动条,我们知道用css来自定义滚动条也是挺好的方式,css虽然能够改变chrome浏览器的滚动条样式可以自定义,css也能够改变IE浏览器滚动条的颜色.但是css ...
- ASP.NET Aries 入门开发教程8:树型列表及自定义右键菜单
前言: 前面几篇重点都在讲普通列表的相关操作. 本篇主要讲树型列表的操作. 框架在设计时,已经把树型列表和普通列表全面统一了操作,用法几乎是一致的. 下面介绍一些差距化的内容: 1:树型列表绑定: v ...
- ASP.NET Aries 入门开发教程5:自定义列表页工具栏区
前言: 抓紧时间,继续写教程,因为发现用户期待的内容,都在业务处理那一块. 不得不继续勤劳了. 这节主要介绍工具栏区的玩法. 工具栏的默认介绍: 工具栏默认包括5个按钮,根据不同的权限决定显示: 添加 ...
- UWP中实现自定义标题栏
UWP中实现自定义标题栏 0x00 起因 在UWP开发中,有时候我们希望实现自定义标题栏,例如在标题栏中加入搜索框.按钮之类的控件.搜了下资料居然在一个日文网站找到了一篇介绍这个主题的文章: http ...
- JavaScript 自定义对象
在Js中,除了Array.Date.Number等内置对象外,开发者可以通过Js代码创建自己的对象. 目录 1. 对象特性:描述对象的特性 2. 创建对象方式:对象直接量.new 构造函数.Objec ...
随机推荐
- Spark排序之SortByKey
sortByKey函数作用于Key-Value形式的RDD,并对Key进行排序. package com.test.spark import org.apache.spark.{SparkConf, ...
- Ubuntu 下 Sublime 无法输入中文?(已解决)
在 Ubuntu 里安装了 Sublime 却不能输入中文? 这可不好. 怎么办呢? Follow Me! 1 获得 sublime-imfix.c 文件 有 GitHub 账号的,可以从 https ...
- Clover 3 --- Windows Explorer 资源管理器的一个扩展,为其增加类似谷歌 Chrome 浏览器的多标签页功能。
http://cn.ejie.me/ http://cn.ejie.me/uploads/setup_clover@3.4.6.exe 软件下载 默认图标实在比较难看,更换图标 更改图标---选择图 ...
- yii2优化 - 开启 Schema 缓存
开启 Schema 缓存 Schema 缓存是一个特殊的缓存功能,每当你使用活动记录时应该要开启这个缓存功能.如你所知, 活动记录能智能检测数据库对象的集合(例如列名.列类型.约束)而不需要手动地描述 ...
- oracle中如何生成awr报告
oracle中如何生成awr报告 1.进入数据库 sqlplus / as sysdba 2.查看用户 show parameter db_name 3.开始压测后执行 exec DBMS_WOR ...
- LightOJ 1224 - DNA Prefix - [字典树上DFS]
题目链接:https://cn.vjudge.net/problem/LightOJ-1224 Given a set of $n$ DNA samples, where each sample is ...
- BZOJ 3224 - 普通平衡树 - [Treap][Splay]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3224 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中 ...
- [No0000FA]C# 接口(Interface)
接口定义了所有类继承接口时应遵循的语法合同.接口定义了语法合同 "是什么" 部分,派生类定义了语法合同 "怎么做" 部分. 接口定义了属性.方法和事件,这些都是 ...
- 模板倍增LCA 求树上两点距离 hdu2586
http://acm.hdu.edu.cn/showproblem.php?pid=2586 课上给的ppt里的模板是错的,wa了一下午orz.最近总是被坑啊... 题解:树上两点距离转化为到根的距离 ...
- python selenium配置
写该博客时环境 mac 10.14.1 (18B75) python 3.7 pip (不用这个就是了,用pip3) $ pip --version pip 10.0.1 from /Users/wj ...