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

iOS-Quart2D 进度条

时间:2015-09-09 17:06:38      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

//
//  HMProgressView.h
//  进度条
//
//  Created by YaguangZhu on 15/9/9.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface HMProgressView : UIView

@property(nonatomic,assign)CGFloat progress;

@end


//
//  HMProgressView.m
//  进度条
//
//  Created by YaguangZhu on 15/9/9.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import "HMProgressView.h"
@interface HMProgressView()

@property(nonatomic,weak)UILabel *label;
@end

@implementation HMProgressView
- (UILabel *)label
{
    if (_label == nil) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        _label = label;
    }
    return _label;
}

- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    self.label.text = [NSString stringWithFormat:@"%.2f%%",progress*100];
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGPoint center = CGPointMake(50, 50);
    CGFloat startA = -M_PI_2;
    CGFloat radius = 50-2;
    CGFloat endA = -M_PI_2 +_progress * M_PI *2;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
    
     CGContextAddPath(ctx, path.CGPath);
    
    CGContextStrokePath(ctx);
    
   
}


@end
//
//  ViewController.h
//  进度条
//
//  Created by YaguangZhu on 15/9/9.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end



//
//  ViewController.m
//  进度条
//
//  Created by YaguangZhu on 15/9/9.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import "ViewController.h"
#import "HMProgressView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet HMProgressView *progressView;

@end

@implementation ViewController
- (IBAction)valueChange:(UISlider *)sender {
    _progressView.progress = sender.value;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

iOS-Quart2D 进度条

标签:

原文地址:http://www.cnblogs.com/zhuyaguang/p/4794994.html

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