CAShapeLayer 使用详解

CAShapeLayer 使用详解

//
//  JFProcessView.m
//  test_JFProcessView_01
//
//  Created by jeffasd on 16/7/4.
//  Copyright © 2016年 jeffasd. All rights reserved.
//

#import "JFProcessView.h"

@interface JFProcessView ()

@property (nonatomic, strong) CAShapeLayer *shapeLayer;



@end

@implementation JFProcessView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        [self initShapeLayer];
        
    }
    
    return self;
}

- (void)initShapeLayer{
    
    self.shapeLayer = [CAShapeLayer layer];
}

- (void)configUIWithFrame:(CGRect)frame{
    
//    self.shapeLayer = [CAShapeLayer layer];
//    self.shapeLayer.frame = self.bounds;
//    
    self.shapeLayer.lineWidth = self.frame.size.height;
//    
//    self.shapeLayer.lineWidth = 2;
//    
//    self.shapeLayer.fillColor = [UIColor redColor].CGColor;
//    self.shapeLayer.strokeColor = [UIColor orangeColor].CGColor;
//    self.shapeLayer.lineCap = kCALineCapRound;
//    UIBezierPath *singleLinePath = [[UIBezierPath alloc] init];
//    
//    
//    
    [singleLinePath moveToPoint:CGPointMake(0, self.frame.size.height/2)];
    [singleLinePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height/2)];
//    
//    
//    
//    [singleLinePath moveToPoint:CGPointMake(0, 0)];
//    [singleLinePath addLineToPoint:CGPointMake(0, self.frame.size.height)];
//    [singleLinePath addArcWithCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height) radius:self.frame.size.width/2 startAngle:0 endAngle:M_PI clockwise:YES];
//    [singleLinePath addLineToPoint:CGPointMake(0, self.frame.size.height)];
//    [singleLinePath moveToPoint:CGPointMake(0, self.frame.size.height)];
//    [singleLinePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];
//    
//    
//    _shapeLayer.fillColor = [UIColor blueColor].CGColor;
//    _shapeLayer.path = singleLinePath.CGPath;
//    _shapeLayer.strokeStart = 0.0;
//    _shapeLayer.strokeEnd = 1.0;
//    [self.layer addSublayer:_shapeLayer];
    
//    self.shapeLayer = [CAShapeLayer layer];
        self.shapeLayer.frame = self.bounds;
    
//    self.shapeLayer.frame = CGRectMake(0, 200, 375, 500);
    
    //    self.shapeLayer.lineWidth = self.frame.size.height;
    
    self.shapeLayer.lineWidth = 2;
    
//    self.shapeLayer.fillColor = [UIColor redColor].CGColor;
    self.shapeLayer.strokeColor = [UIColor clearColor].CGColor;
    self.shapeLayer.lineCap = kCALineCapRound;
    UIBezierPath *singleLinePath = [[UIBezierPath alloc] init];
    
    
    
    //    [singleLinePath moveToPoint:CGPointMake(0, self.frame.size.height/2)];
    //    [singleLinePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height/2)];
    
    
    int width = self.frame.size.width;
    
    int height = self.frame.size.height;
    
//    width = 300;
//    height = 30;
    
    int start = 0;
    
    [singleLinePath moveToPoint:CGPointMake(start, start)];
    [singleLinePath addLineToPoint:CGPointMake(width+start-height/2, 0+start)];
    [singleLinePath addArcWithCenter:CGPointMake(width+start-height/2, height/2+start) radius:height/2 startAngle:-M_PI/2 endAngle:M_PI/2 clockwise:YES];
    [singleLinePath addLineToPoint:CGPointMake(start, height+start)];
    [singleLinePath addLineToPoint:CGPointMake(start, start)];
    
    
    _shapeLayer.fillColor = [UIColor blueColor].CGColor;
    _shapeLayer.path = singleLinePath.CGPath;
    _shapeLayer.strokeStart = 0.0;
    _shapeLayer.strokeEnd = 1.0;
    [self.layer addSublayer:_shapeLayer];
    
}

- (void)setProgressTintColor:(UIColor *)progressTintColor{
    
//    self.shapeLayer.strokeColor = _progressTintColor.CGColor;
}

- (void)setTrackTintColor:(UIColor *)trackTintColor{
//    self.backgroundColor = trackTintColor;
}

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值