iOS开发圆环精度

释放双眼,带上耳机,听听看~!

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

为TA充电
共{{data.count}}人
人已赞赏
iOS文章

iOS开发通过导航栏切换页面动画

2021-5-6 12:47:11

iOS文章

iOS--App功耗优化

2021-5-6 12:50:55

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索