• 自定义圆形进度条


    #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

  • 相关阅读:
    Chrome下的语音控制框架MyVoix.js使用篇(二)
    Chrome下的语音控制框架MyVoix.js使用篇(三)
    Echarts X轴多项百分比的展示
    jsMind思维导图模式展示数据
    使用SqlBulkCopy将DataTable百万级数据瞬间入库
    SQL根据指定节点ID获取所有父级节点和子级节点
    让div在body中任意拖动
    ASP.NET MVC使用jQuery实现Autocomplete
    Django简介
    注册表单
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4386091.html
Copyright © 2020-2023  润新知