了解 CAGradient 位置?

发布于 2024-10-25 19:25:28 字数 1440 浏览 1 评论 0原文

我正在创建一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2024-11-01 19:25:29
  1. 您正在多个停靠位置定义上使用 [NSNumber numberWithInt:]。使用[NSNumber numberWithFloat:]
  2. 颜色数量应与停止数量相同。您有 5 种颜色和 8 个停靠点。添加 3 种颜色或删除 3 个停止位置。
  1. You are using [NSNumber numberWithInt:] on several of the stop location definitions. Use [NSNumber numberWithFloat:].
  2. The number of colors should be the same as the number of stops. You have 5 colors and 8 stop locations. Either add 3 colors or remove 3 stop locations.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文