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












IOS 之圆形 ProgressView,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。