zoukankan      html  css  js  c++  java
  • 使用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
    

      

  • 相关阅读:
    完美解决微信端设置title失败问题
    linux下的find&&grep查找命令
    微信开发二三事
    干掉chrome下input恶心的黄色背景
    关于.gitignore文件使用说明
    HTTPie:一个不错的 HTTP 命令行客户端
    退出登录功能改变window的rootviewcontroller输入框键盘不会收起
    coredata操作工具
    并发编程gcd粗暴记忆法
    网友的百度移动云可穿戴部门的面试经历
  • 原文地址:https://www.cnblogs.com/sixindev/p/4834343.html
Copyright © 2011-2022 走看看