Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertical color gradient

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?

like image 563
darshan Avatar asked Aug 16 '10 05:08

darshan


People also ask

What are the three types of gradients?

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)

What is linear gradient?

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> .

What is an example of the color gradient?

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).


2 Answers

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.

like image 174
Matt Long Avatar answered Oct 04 '22 19:10

Matt Long


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).

like image 44
Dave DeLong Avatar answered Oct 04 '22 19:10

Dave DeLong