From 6406bfdcef916d6aaad3254b6738c302c9fb65f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Sat, 9 May 2020 11:14:46 +0800 Subject: [PATCH] iOS: implements multiple segments as gradient color --- doric-iOS/Pod/Classes/Shader/DoricViewNode.m | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m index 838d8964..0529a91e 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m @@ -341,8 +341,20 @@ - (void)requestLayout { return; } self.gradientSize = self.view.frame.size; - UIColor *start = DoricColor(dict[@"start"]); - UIColor *end = DoricColor(dict[@"end"]); + NSMutableArray *colors = [[NSMutableArray alloc] init]; + if ([dict objectForKey:@"colors"] != nil) { + NSMutableArray *array = [dict mutableArrayValueForKey:@"colors"]; + [array forEach:^(id obj) { + [colors addObject:(__bridge id) DoricColor(obj).CGColor]; + }]; + } else { + UIColor *start = DoricColor(dict[@"start"]); + UIColor *end = DoricColor(dict[@"end"]); + + [colors addObject:(__bridge id) start.CGColor]; + [colors addObject:(__bridge id) end.CGColor]; + } + int orientation = [dict[@"orientation"] intValue]; CGPoint startPoint; CGPoint endPoint; @@ -371,7 +383,7 @@ - (void)requestLayout { startPoint = CGPointMake(0, 0); endPoint = CGPointMake(0, 1); } - UIImage *gradientImage = [self gradientImageFromColors:@[(__bridge id) start.CGColor, (__bridge id) end.CGColor] + UIImage *gradientImage = [self gradientImageFromColors:colors startPoint:startPoint endPoint:endPoint imgSize:self.gradientSize];