码迷,mamicode.com
首页 > 移动开发 > 详细

IOS 之圆形 ProgressView

时间:2014-06-15 18:24:52      阅读:871      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   tar   

今天有个需求要制作圆形的UIProgressView 我采用的是一个开源的DACircularProgress,给大家分享一下

一,介绍:

1.GitHub下载地址:https://github.com/danielamitay/DACircularProgress

2.最后效果图如下:

bubuko.com,布布扣bubuko.com,布布扣



二.步骤:

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,布布扣,bubuko.com

IOS 之圆形 ProgressView

标签:style   class   blog   code   http   tar   

原文地址:http://blog.csdn.net/wildcatlele/article/details/30290491

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!