• 自定义圆形进度条


    #import <UIKit/UIKit.h>
    
    @interface CircleProgressView : UIView
    
    /**进度值*/
    @property(nonatomic,assign) CGFloat  progressValue;
    
    @end
    #import "CircleProgressView.h"
    
    @implementation CircleProgressView
    @synthesize progressValue = _progressValue;
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self)
        {
            
            self.backgroundColor = [UIColor clearColor];
        }
        return self;
    }
    
    - (void)setProgressValue:(CGFloat)progressValue
    {
        _progressValue = progressValue;
        [self setNeedsDisplay];
        
    }
    
    - (CGFloat)progressValue
    {
        return _progressValue;
    
    }
    
    - (void)drawRect:(CGRect)rect
    {
        CGContextRef contextRef = UIGraphicsGetCurrentContext();
        CGFloat radius = rect.size.width/2;
        
        /**绘制一个灰色背景的圆形*/
        CGContextAddArc(contextRef, radius, radius, radius, 0, 3.141596253*2, 0);
        CGContextSetRGBFillColor(contextRef, 0.7, 0.7, 0.7, 1);
        CGContextFillPath(contextRef);
        
        /**绘制一个动态圆形*/
        CGContextAddArc(contextRef, radius, radius, radius, 0, 3.14 * _progressValue * 2, 0);
        CGContextAddLineToPoint(contextRef, radius, radius);
        CGContextSetRGBFillColor(contextRef, 0, 0, 1, 1);
        CGContextFillPath(contextRef);
    
    }
    @end
    #import "ViewController.h"
    #import "CircleProgressView.h"
    @interface ViewController ()
    {
    
       CircleProgressView *_vCircleProgress;
       NSTimer *_timer;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        _vCircleProgress = [[CircleProgressView alloc]initWithFrame:CGRectMake(0,0, 100, 100)];
        _vCircleProgress.center = self.view.center;
        [self.view addSubview:_vCircleProgress];
        _timer=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(changeProgressValue) userInfo:nil repeats:YES];
    
    }
    - (void)changeProgressValue
    {
        CGFloat value = arc4random()%100/100.f;
        _vCircleProgress.progressValue = value;
    }
    
    @end

  • 相关阅读:
    1349:【例4-10】最优布线问题
    1348:【例4-9】城市公交网建设问题
    P2024 [NOI2001]食物链
    $P2573 [SCOI2012]滑雪$
    $P1991 无线通讯网$
    $P2872 [USACO07DEC]道路建设Building Roads$
    $P1547 Out of Hay$
    hdu 3468 Treasure Hunting
    hungary HK 多重匹配
    Hdu匹配题集
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4386091.html
Copyright © 2020-2023  润新知