我正在创建一个带有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;
但我得到一个完全黑色的酒吧。当我删除位置时,我看到了完美的渐变,但它没有很好地划分。
我觉得我不太了解这些位置。
任何帮助?
答案 0 :(得分:3)
[NSNumber numberWithInt:]
。使用[NSNumber numberWithFloat:]
。