垂直颜色渐变

发布于 2024-09-14 23:14:03 字数 91 浏览 2 评论 0原文

水平渐变效果很好。有没有办法从水平渐变获得垂直颜色渐变? 我看到了一个与此相关的问题,他们通过旋转框架来做到这一点。

有没有更简单的方法来实现垂直渐变?

Horizontal gradient is working fine. Is there any way to get a vertical color gradient from horizontal gradient?
I have seen a related question regarding this where they did this by rotating the frames.

Is there any simpler way to achieve a vertical gradient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

久而酒知 2024-09-21 23:14:04

默认的 startPointendPoint 将使渐变从上到下显示您的颜色(在我看来,这是一个垂直渐变)。如果您希望渐变从左到右显示(在我看来,这是一个水平渐变),请在您的 CAGradientLayer 上使用此代码:

  [gradientLayer setStartPoint:CGPointMake(0.0, 0.5)];
  [gradientLayer setEndPoint:CGPointMake(1.0, 0.5)];

不需要 3D 变换。

The default startPoint and endPoint would have the gradient display your colors from top to bottom (which in my mind is a vertical gradient). If you want the gradient to display from left to right (again in my mind this is a horizontal gradient), use this code on your CAGradientLayer:

  [gradientLayer setStartPoint:CGPointMake(0.0, 0.5)];
  [gradientLayer setEndPoint:CGPointMake(1.0, 0.5)];

A 3D transform is unnecessary.

温柔一刀 2024-09-21 23:14:04

旋转90°怎么样?

编辑从您的评论来看,您似乎是通过CAGradientLayer执行此操作。 CAGradientLayerCALayer 的子类,它具有 transform 属性。此 transform 属性采用一个 CATransform3D,它是一个结构体,表示要应用于图层的某种线性变换(例如缩放、平移或旋转)。

所以实际上你只需要 制作一个旋转CATransform3D并将其设置为CAGradientLayertransform属性。

您也可以通过摆弄 startPointendPoint 来完成这项工作(实际上可能会更简单)。

How about rotating it 90º?

edit judging from your comment, it seems that you're doing this via CAGradientLayer. CAGradientLayer is a subclass of CALayer, which has a transform property. This transform property takes a CATransform3D, which is a struct that represents some sort of linear transformation to be applied to the layer (such as scaling, translation, or rotation).

So really you just need to make a rotational CATransform3D and set it as the transform property of your CAGradientLayer.

You could probably also make this work by fiddling with the startPoint and endPoint (which would actually probably be simpler).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文