zoukankan      html  css  js  c++  java
  • 圆环精度

    self.slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
        self.slider.center = CGPointMake(CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame)+150);
        [self.view addSubview:self.slider];
        [self.slider addTarget:self action:@selector(actionProgressMove:) forControlEvents:UIControlEventValueChanged];
        
        
        //进度视图
        self.circleSlideView = [[CircleSlideView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
        self.circleSlideView.center = CGPointMake(CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame) - 100);
        [self.view addSubview:self.circleSlideView];
    - (void)actionProgressMove:(UISlider *)slider{
        self.circleSlideView.progress = self.slider.value;
    }

    绘制精度环:

    #import <UIKit/UIKit.h>
    
    @interface CircleSlideView : UIView
    @property (nonatomic, assign) CGFloat progress;
    @end
    #import "CircleSlideView.h"
    
    @interface CircleSlideView ()
    
    @property (nonatomic, strong) CAShapeLayer * backLayer;
    @property (nonatomic, strong) UIBezierPath * backPath;
    
    @property (nonatomic, strong) CAShapeLayer * progressLayer;
    @property (nonatomic, strong) UIBezierPath * progressPath;
    
    @end
    
    @implementation CircleSlideView
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self loadContent];
        }
        return self;
    }
    
    - (void)loadContent {
        //  底部Layer
        self.backLayer = [CAShapeLayer layer];
        self.backLayer.bounds = self.bounds;
        self.backLayer.position = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
        self.backLayer.lineWidth = 10.0;
        self.backLayer.strokeColor = [UIColor lightGrayColor].CGColor;
        self.backLayer.fillColor = [UIColor clearColor].CGColor;
        
        //  设置路径
        self.backPath = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
        self.backLayer.path = self.backPath.CGPath;
        [self.layer addSublayer:self.backLayer];
        
        //  进度layer
        self.progressLayer = [CAShapeLayer layer];
        self.progressLayer.bounds = self.bounds;
        self.progressLayer.position = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
        self.progressLayer.lineWidth = 10.0;
        self.progressLayer.strokeColor = [UIColor purpleColor].CGColor;
        self.progressLayer.fillColor = [UIColor clearColor].CGColor;
        self.progressLayer.lineCap = kCALineCapRound;
        
        //  设置路径
        self.progressPath = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
        self.progressLayer.path = self.progressPath.CGPath;
        [self.layer addSublayer:self.progressLayer];
        
        self.progressLayer.strokeStart = 0;   //路径起始位置
        self.progressLayer.strokeEnd   = 0;   //路径结束位置
    }
    
    - (void)setProgress:(CGFloat)progress {
        if (progress < 0) {
            progress = 0;
        }
        if (progress > 1) {
            progress = 1;
        }
        _progress = progress;
        _progressLayer.strokeEnd = self.progress;
    }
    
    @end
  • 相关阅读:
    [主席树][学习笔记]
    [bzoj2588][ Count on a tree]
    [bzoj3524][Couriers]
    [luogu3834][可持久化线段树 1(主席树)]
    [luogu3810][bzoj3262][陌上花开]
    [树套树][学习笔记]
    [luogu4556][Vani有约会]
    [线段树合并][学习笔记]
    [hdu6183][Color it]
    [动态开点线段树][学习笔记]
  • 原文地址:https://www.cnblogs.com/fengmin/p/8136571.html
Copyright © 2011-2022 走看看