Add lineCap lineJoin and lineDash.

This commit is contained in:
PonyCui
2017-02-21 17:48:58 +08:00
parent 5776ef8248
commit 53b00c4276
2 changed files with 26 additions and 1 deletions

View File

@@ -19,7 +19,7 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.aPlayer];
self.aPlayer.delegate = self;
self.aPlayer.frame = CGRectMake(0, 0, 320, 320);

View File

@@ -22,6 +22,7 @@
self = [super init];
if (self) {
_spec = spec;
self.backgroundColor = [UIColor clearColor].CGColor;
self.masksToBounds = NO;
[self createSublayers:previous];
}
@@ -120,6 +121,7 @@
- (void)resetStyles:(CAShapeLayer *)shapeLayer shape:(NSDictionary *)shape {
shapeLayer.masksToBounds = NO;
shapeLayer.backgroundColor = [UIColor clearColor].CGColor;
if ([shape[@"styles"] isKindOfClass:[NSDictionary class]]) {
if ([shape[@"styles"][@"fill"] isKindOfClass:[NSArray class]]) {
NSArray *colorArray = shape[@"styles"][@"fill"];
@@ -134,6 +136,9 @@
alpha:[colorArray[3] floatValue]].CGColor;
}
}
else {
shapeLayer.fillColor = [UIColor clearColor].CGColor;
}
if ([shape[@"styles"][@"stroke"] isKindOfClass:[NSArray class]]) {
NSArray *colorArray = shape[@"styles"][@"stroke"];
if ([colorArray count] == 4 &&
@@ -150,6 +155,26 @@
if ([shape[@"styles"][@"strokeWidth"] isKindOfClass:[NSNumber class]]) {
shapeLayer.lineWidth = [shape[@"styles"][@"strokeWidth"] floatValue];
}
if ([shape[@"styles"][@"lineCap"] isKindOfClass:[NSString class]]) {
shapeLayer.lineCap = shape[@"styles"][@"lineCap"];
}
if ([shape[@"styles"][@"lineJoin"] isKindOfClass:[NSString class]]) {
shapeLayer.lineJoin = shape[@"styles"][@"lineJoin"];
}
if ([shape[@"styles"][@"lineDash"] isKindOfClass:[NSArray class]]) {
BOOL accept = YES;
for (id obj in shape[@"styles"][@"lineDash"]) {
if (![obj isKindOfClass:[NSNumber class]]) {
accept = NO;
}
}
if (accept) {
shapeLayer.lineDashPattern = shape[@"styles"][@"lineDash"];
}
}
if ([shape[@"styles"][@"miterLimit"] isKindOfClass:[NSNumber class]]) {
shapeLayer.miterLimit = [shape[@"styles"][@"miterLimit"] floatValue];
}
}
}