首页 > 移动平台 > 详细

iOS-Quart2D 进度条

时间:2015-09-09 17:03:36      阅读:238      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!