12

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?

Connor
  • 60,945
  • 26
  • 140
  • 138
darshan
  • 161
  • 1
  • 2
  • 4

2 Answers2

79

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.

Matt Long
  • 23,982
  • 4
  • 70
  • 99
2

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

Dave DeLong
  • 239,073
  • 58
  • 443
  • 495
  • I used gradient.startpoint and gradient.endpoint for rotating... is this ok...? I need 180 degree rotation.. shall I use the same logic as above. – darshan Aug 16 '10 at 06:46