vertical color gradient

darshan picture darshan · Aug 16, 2010 · Viewed 11.1k times · Source

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?

Answer

Matt Long picture Matt Long · Aug 17, 2010

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.