iOS: implements multiple segments as gradient color

This commit is contained in:
王劲鹏 2020-05-09 11:14:46 +08:00 committed by osborn
parent d91142a1db
commit 6406bfdcef

View File

@ -341,8 +341,20 @@ - (void)requestLayout {
return; return;
} }
self.gradientSize = self.view.frame.size; self.gradientSize = self.view.frame.size;
UIColor *start = DoricColor(dict[@"start"]); NSMutableArray *colors = [[NSMutableArray alloc] init];
UIColor *end = DoricColor(dict[@"end"]); 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]; int orientation = [dict[@"orientation"] intValue];
CGPoint startPoint; CGPoint startPoint;
CGPoint endPoint; CGPoint endPoint;
@ -371,7 +383,7 @@ - (void)requestLayout {
startPoint = CGPointMake(0, 0); startPoint = CGPointMake(0, 0);
endPoint = CGPointMake(0, 1); endPoint = CGPointMake(0, 1);
} }
UIImage *gradientImage = [self gradientImageFromColors:@[(__bridge id) start.CGColor, (__bridge id) end.CGColor] UIImage *gradientImage = [self gradientImageFromColors:colors
startPoint:startPoint startPoint:startPoint
endPoint:endPoint endPoint:endPoint
imgSize:self.gradientSize]; imgSize:self.gradientSize];