首页 > 代码库 > IOS 之圆形 ProgressView
IOS 之圆形 ProgressView
今天有个需求要制作圆形的UIProgressView 我采用的是一个开源的DACircularProgress,给大家分享一下
一,介绍:
1.GitHub下载地址:https://github.com/danielamitay/DACircularProgress
2.最后效果图如下:
二.步骤:
1.从GitHub下载DACircularProgress ,解压缩
2.把DACircularProgress文件夹拖入项目中
3.添加<QuartzCore.framework>
.框架
4.在ViewController中添加头文件 #import "DACircularProgressView.h"
5.使用如下:
self.progressView = [[DACircularProgressView alloc] initWithFrame:CGRectMake(140.0f, 30.0f, 40.0f, 40.0f)]; self.progressView.roundedCorners = YES; self.progressView.trackTintColor = [UIColor clearColor]; [self.view addSubview:self.progressView];
转载请注明,本文转自:http://blog.csdn.net/wildcatlele
6.我做的项目要求进度有一个递增的进度,在我项目中使用如下,很简单直接上代码:
#import "ViewController.h" //#import "WeekDay.h" //#import "GetCityAQI.h" //#import "CityAQI.h" //#import "TestView.h" #import "DACircularProgressView.h" #import "DALabeledCircularProgressView.h" #define TIMER_DURATION 5 #define AQI_FULL 500 @interface ViewController (){ DACircularProgressView *progressView; DALabeledCircularProgressView *labeledProgressView; int start; int aqi; } @property (nonatomic,retain )NSTimer *timer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self setProgressView]; } #pragma mark - 进度条 -(void)setProgressView{ //设置空气质量指数 aqi=200; //初始化进度条视图 progressView = [[DACircularProgressView alloc] initWithFrame:CGRectMake(140.0f, 200.0f, 100.0f, 100.0f)]; progressView.roundedCorners = NO; //设置颜色 progressView.trackTintColor = [UIColor grayColor]; progressView.progressTintColor=[UIColor greenColor]; //设置进度 [progressView setProgress:(CGFloat)aqi/AQI_FULL animated:YES initialDelay:0.5]; labeledProgressView= [[DALabeledCircularProgressView alloc] initWithFrame:CGRectMake(140.0f, 200.0f, 100.0f, 100.0f)]; labeledProgressView.progressLabel.textColor=[UIColor blueColor]; [self.view addSubview:labeledProgressView]; [self.view addSubview:progressView]; [self startAnimation]; } #pragma mark 开始启动定时器 标签内容自加 - (void)startAnimation { self.timer= [NSTimer scheduledTimerWithTimeInterval:(CGFloat)TIMER_DURATION/aqi target:self selector:@selector(progressChange) userInfo:nil repeats:YES]; } #pragma mark 改变标签内容 - (void)progressChange { labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%d", start+=1]; if (start>=aqi) { [self.timer invalidate]; self.timer = nil; } } @end
转载请注明,本文转自:http://blog.csdn.net/wildcatlele
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。