標籤:style class blog code http tar
今天有個需求要製作圓形的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