【发布时间】:2011-03-24 14:38:41
【问题描述】:
我正在创建一个带有 CAGradient 层的简单条形图。我有 6 种颜色希望在图层上均匀分布。
NSMutableArray *colors = [NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:.95] CGColor],
(id)[[UIColor colorWithRed:204.0/255.0 green:153.0/255.0 blue:0/255.0 alpha:.95]CGColor],
(id)[ [UIColor colorWithRed:204.0/255.0 green:102.0/255.0 blue:51.0/255.0 alpha:.95]CGColor],
(id)[ [UIColor colorWithRed:204.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:.95]CGColor],
(id)[ [UIColor blackColor]CGColor],nil];
NSMutableArray *locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithInt:0.14],
[NSNumber numberWithInt:0.28],
[NSNumber numberWithInt:0.42],
[NSNumber numberWithInt:0.56],
[NSNumber numberWithInt:0.70],
[NSNumber numberWithInt:0.84],
[NSNumber numberWithInt:1.0],nil];
并用 :
实现它们 gradientLayer_.colors =colors;
gradientLayer_.locations=locations;
但我得到一个完全黑条。当我删除位置时,我可以完美地看到渐变,但没有很好地分割。
我觉得我不太了解这些位置。
有什么帮助吗?
【问题讨论】: