lreddy
lreddy

Reputation: 479

How to set the gradient angle and type to the CAGradientLayer

Hi i am trying to get the color from the gradients where that color is set to another view . I am able to set start and end color,but not able to set the angle and the type.

Here are the values: 1.Startcolor:@"2b2b2b" 2.Endcolor:@"4a4a4a" 3.GradientAngle:90 4.GradientType:@"linear"

UIView *theView=[[UIView alloc] init];
theView.frame=self.view.frame; 
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = theView.bounds;
UIColor *startColor = [self colorwithHexString:@"2b2b2b" alpha:1];
UIColor *endColor = [self colorwithHexString:@"4a4a4a" alpha:1];
gradient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor], (id)[endColor CGColor], nil];
[theView.layer insertSublayer:gradient atIndex:0];

Upvotes: 1

Views: 2074

Answers (1)

David Rönnqvist
David Rönnqvist

Reputation: 56625

CAGradientLayer has a type property (but the only supported value is axial):

An axial gradient (also called a linear gradient) varies along an axis between two defined end points. All points that lie on a line perpendicular to the axis have the same color value.

The angle is determined by the startPoint and endPoint properties. Both are defined in the unit coordinate space of the layer's bounds (x and y range from 0 to 1).

Upvotes: 2

Related Questions