// // MainViewController.m // fitmiss // // Created by bill on 13-4-11. // Copyright (c) 2013年 lear. All rights reserved. // #import "MainViewController.h" #import "RootTabBarController.h" #import "MLNavigationController.h" #import "THCircularProgressView.h" #import "Function.h" #import "textViewController.h" @interface MainViewController () @property (nonatomic, strong) NSTimer *timer; @property (nonatomic) CGFloat percentage; @property (nonatomic) CGFloat percentageEnd; @property (nonatomic) THCircularProgressView *roundProgressBar; @end @implementation MainViewController -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.percentage = 0; self.percentageEnd = 0.75; self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.roundProgressBar.percentage = 0; [self.timer invalidate]; } - (void)viewDidLoad { [super viewDidLoad]; UIView *rootView = [[UIView alloc]init]; rootView.frame = CGRectMake(0, 0, [Function getScreenWidth], [Function getScreenHeight] - 49); rootView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:rootView]; //主要区域 UIView *taskView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [Function getScreenWidth], 216)]; taskView.backgroundColor = [Function colorWithHexString:@"#f5f0eb"]; [rootView addSubview:taskView]; //添加圆---------------------------------------------------------------- UIView *roundView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, 176, 176)]; //添加圆形的进度条 self.percentage = 0; //self.percentageEnd = 1; self.roundProgressBar = [[THCircularProgressView alloc] initWithCenter:CGPointMake(88, 88) radius:87 lineWidth:88.0f progressMode:THProgressModeFill progressColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"round_show"]] progressBackgroundMode:THProgressBackgroundModeCircumference progressBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"round_bg"]] percentage:self.percentage]; [roundView addSubview:self.roundProgressBar]; //添加圆的按钮及上面的文字 UIImage *roundButtonImg = [UIImage imageNamed:@"round_button"]; UIButton *roundButton = [UIButton buttonWithType:UIButtonTypeCustom]; roundButton.frame = CGRectMake(22, 22, roundButtonImg.size.width, roundButtonImg.size.height); [roundButton setBackgroundImage:roundButtonImg forState:UIControlStateNormal]; UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 132, 132)]; buttonLabel.backgroundColor = [UIColor clearColor]; buttonLabel.text = @"08"; buttonLabel.textAlignment = 1; buttonLabel.shadowColor = [UIColor grayColor]; buttonLabel.shadowOffset = CGSizeMake(0.5,0.5); buttonLabel.textColor = [Function colorWithHexString:@"#3f3f3f"]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) { buttonLabel.font = [UIFont fontWithName:@"Avenir Next Condensed" size:70.0f]; }else{ buttonLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:60.0f]; } [roundButton addTarget:self action:@selector(renwuButtenClick:) forControlEvents:UIControlEventTouchUpInside]; [roundButton addSubview:buttonLabel]; UILabel *buttonLabelTop = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 132, 30)]; buttonLabelTop.backgroundColor = [UIColor clearColor]; buttonLabelTop.text = @"未完成任务"; buttonLabelTop.textAlignment = 1; buttonLabelTop.textColor = [Function colorWithHexString:@"#555555"]; buttonLabelTop.font = [UIFont systemFontOfSize:11]; [roundButton addSubview:buttonLabelTop]; UILabel *buttonLabelButtom = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, 132, 30)]; buttonLabelButtom.backgroundColor = [UIColor clearColor]; buttonLabelButtom.text = @"点击执行"; buttonLabelButtom.textAlignment = 1; buttonLabelButtom.textColor = [Function colorWithHexString:@"#555555"]; buttonLabelButtom.font = [UIFont systemFontOfSize:14]; [roundButton addSubview:buttonLabelButtom]; [roundView addSubview:roundButton]; //--------------------------------------------------------------------- [taskView addSubview:roundView]; } - (void)timerFired:(NSTimer *)timer { self.percentage += 0.01; if (self.percentage >= self.percentageEnd) { [self.timer invalidate]; } self.roundProgressBar.percentage = self.percentage; } @end
THCircularProgressView.h 的使用方法
时间: 2024-10-21 17:50:01