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
  • 相关阅读:
    WC项目
    团队项目(MVP新能源无线充电管理网站)(总结)
    学期目标
    个人目标、思维导图、不同点
    结对项目——黄金分割点游戏(陈香宇&蔡春燕)
    团队项目(MVP新能源无线充电管理网站)(个人任务2)
    四则运算
    读后疑问
    crontab 定时任务
    mysql主从配置
  • 原文地址:https://www.cnblogs.com/fengmin/p/8136571.html
Copyright © 2011-2022 走看看