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?
CSS defines three types of gradients: Linear Gradients (goes down/up/left/right/diagonally) Radial Gradients (defined by their center) Conic Gradients (rotated around a center point)
linear-gradient() The linear-gradient() CSS function creates an image consisting of a progressive transition between two or more colors along a straight line. Its result is an object of the <gradient> data type, which is a special kind of <image> .
Gradients can blend or transition similar colors (so, for example, different shades of blue or a light orange to a dark red) or completely different or contrasting colors (like purple and red or blue and yellow).
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With