垂直颜色渐变
水平渐变效果很好。有没有办法从水平渐变获得垂直颜色渐变? 我看到了一个与此相关的问题,他们通过旋转框架来做到这一点。
有没有更简单的方法来实现垂直渐变?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认的 startPoint 和 endPoint 将使渐变从上到下显示您的颜色(在我看来,这是一个垂直渐变)。如果您希望渐变从左到右显示(在我看来,这是一个水平渐变),请在您的 CAGradientLayer 上使用此代码:
不需要 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:
A 3D transform is unnecessary.
旋转90°怎么样?
编辑从您的评论来看,您似乎是通过
CAGradientLayer
执行此操作。CAGradientLayer
是CALayer
的子类,它具有transform
属性。此transform
属性采用一个CATransform3D
,它是一个结构体,表示要应用于图层的某种线性变换(例如缩放、平移或旋转)。所以实际上你只需要 制作一个旋转
CATransform3D
并将其设置为CAGradientLayer
的transform
属性。您也可以通过摆弄
startPoint
和endPoint
来完成这项工作(实际上可能会更简单)。How about rotating it 90º?
edit judging from your comment, it seems that you're doing this via
CAGradientLayer
.CAGradientLayer
is a subclass ofCALayer
, which has atransform
property. Thistransform
property takes aCATransform3D
, 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 thetransform
property of yourCAGradientLayer
.You could probably also make this work by fiddling with the
startPoint
andendPoint
(which would actually probably be simpler).