下载进度指示器初版。。。


快过年了,这几天手上也没有项目,于是自己就开始写一些小Demo,这个就是可以用于提示图片下载进度的一个指示器。

.h文件

#import <UIKit/UIKit.h>

@interface CustomView : UIView
/**
 *  0<=hudValue  && hudValue<=1
 */
@property (nonatomic, assign) CGFloat hudValue;
@end

.m文件

#import "CustomView.h"

@implementation CustomView
{
    CGFloat _trValue;
}
- (void)setHudValue:(CGFloat)hudValue
{
    if (hudValue >1)
    {
        _hudValue = 1;
    }else
    if (hudValue <0)
    {
        _hudValue = 0;
    }else
    {
        _hudValue = hudValue;
    }
    _trValue = (_hudValue/1.0f) *360.0f - 90.0f;
    [self setNeedsDisplay];
}


- (void)drawRect:(CGRect)rect
{
    CGFloat w = self.frame.size.width;
    CGFloat h = self.frame.size.height;
    [[UIImage imageNamed:@"image"] drawAsPatternInRect:CGRectMake(0.0f, 0.0f,w, h)];
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, w * 0.5f, h * 0.5f);
    CGContextAddArc(ctx, w * 0.5f, h * 0.5f,h * 0.5f, 270.0f * (M_PI/180.0f), _trValue* (M_PI/180.0f),0);
    CGContextClosePath(ctx);
    CGContextSetRGBFillColor(ctx, 1.0f, 0.0f, 0.0f, 0.4f);
    CGContextFillPath(ctx);
}


控制器代码片段

@implementation ViewController
{
    CustomView *_hudView;

}
- (void)viewDidLoad {
    [super viewDidLoad];
//    [UITableView]
    CustomView *view = [[CustomView alloc]initWithFrame:CGRectMake(0.0f, 64.0f, self.view.frame.size.width, self.view.frame.size.width)];
    [view setBackgroundColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f]];

    [self.view addSubview:view];
    view.hudValue = 1.0f;
    _hudView = view;
}

- (IBAction)btnAction:(id)sender
{
    _hudView.hudValue = 1.0f;
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
}

- (void)timerAction:(NSTimer *)timer
{
    
    if (_hudView.hudValue >0)
    {
        _hudView.hudValue = _hudView.hudValue-0.01f;
    }else
    {
        [timer invalidate];
    }

}


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

@end


效果图如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值