views:

35

answers:

2

Horizontal gradient is working fine . Is there any property to get vertical color gradient from horizontal gradient. I have seen the related question regarding this where they have explained using rotating the frames...

so, is there any simpler way to achieve vertical gradient..

+1  A: 

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
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
@darshan edited answer
Dave DeLong
A: 

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