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