• 使用CAShapeLayer做出圆形的进度条 —— #DF!


    CircleView.h的内容如下:
    
    #import <UIKit/UIKit.h>
    
    @interface CircleView : UIView
    
    @property (nonatomic, assign) CGFloat  startValue; 
    @property (nonatomic, assign) CGFloat  lineWidth;
    @property (nonatomic, strong) UIColor *lineColor;
    @property (nonatomic, assign) CGFloat  value;
    
    @end
    
    
    ===================
    
    
    CircleView.m的内容如下:
    
    #import "CircleView.h"
    
    @interface CircleView ()
    
    @property (nonatomic, strong) CAShapeLayer *shapeLayer;
    
    @end
    
    @implementation CircleView
    
    - (instancetype)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
            _shapeLayer       = [CAShapeLayer layer];
            _shapeLayer.frame = self.bounds;
            
            UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
            
            _shapeLayer.path = path.CGPath;
            
            _shapeLayer.fillColor   = [UIColor clearColor].CGColor;
            _shapeLayer.lineWidth   = 1.f;
            _shapeLayer.strokeColor = [UIColor redColor].CGColor;
            _shapeLayer.strokeEnd   = 0.f;
            
            [self.layer addSublayer:_shapeLayer];
        }
        return self;
    }
    
    @synthesize startValue = _startValue;
    - (void)setStartValue:(CGFloat)startValue {
        _startValue           = startValue;
        _shapeLayer.strokeEnd = startValue;
    }
    - (CGFloat)startValue {
        return _startValue;
    }
    
    @synthesize lineWidth = _lineWidth;
    - (void)setLineWidth:(CGFloat)lineWidth {
        _lineWidth            = lineWidth;
        _shapeLayer.lineWidth = lineWidth;
    }
    - (CGFloat)lineWidth {
        return _lineWidth;
    }
    
    @synthesize lineColor = _lineColor;
    - (void)setLineColor:(UIColor *)lineColor {
        _lineColor              = lineColor;
        _shapeLayer.strokeColor = lineColor.CGColor;
    }
    - (UIColor *)lineColor {
        return _lineColor;
    }
    
    @synthesize value = _value;
    - (void)setValue:(CGFloat)value {
        _value                = value;
        _shapeLayer.strokeEnd = value;
    }
    - (CGFloat)value {
        return _value;
    }
    
    @end
    

      

  • 相关阅读:
    Eclipse 卸载插件
    ubuntu下载linuxkernel source code
    Android原生态下载错误解决方法
    linux下查看文件或者文件夹属性和大小
    linux 进行hash校验方法
    Mercury迷你150M无线路由器设置
    xubuntu 12.10 安装jdk1.6
    Linux下stardic和goldendict等词典的词库下载
    Web前端面试指导(九):盒子模型你是怎么理解的?
    Web前端面试指导(十二):::before 和:before有什么区别?
  • 原文地址:https://www.cnblogs.com/sixindev/p/4834343.html
Copyright © 2020-2023  润新知