了解 CAGradient 位置?
我正在创建一个带有 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;
但我得到一个完全黑色的条来实现它们。当我删除位置时,我可以完美地看到渐变,但它没有很好地划分。
我觉得我不太了解这些地点。
有什么帮助吗?
i am creating a simple bar with a CAGradient layer. i have 6 colors that i want to be spread equally on the layer.
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];
and implement them with :
gradientLayer_.colors =colors;
gradientLayer_.locations=locations;
But I am getting a totally black bar. when i remove the locations i see the gradient perfectly but it is not divided well.
I feel that i don't understand the locations well.
any help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[NSNumber numberWithInt:]
。使用[NSNumber numberWithFloat:]
。[NSNumber numberWithInt:]
on several of the stop location definitions. Use[NSNumber numberWithFloat:]
.