Alex Muller
Alex Muller

Reputation: 1565

Display gradient along left edge of UIView

I am trying to draw a shadow along the side of a UIView so that it gives it a 3D-esque appearance. A variation of this works for a vertical gradient along the bottom of another view, however I am trying to achieve a horizontal gradient along the left side of the view. Below is my attempt. I get a color, however there is not a gradient to it.

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(-5, 0, 5, kScreenHeight);
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1.0, 0.5);
gradient.colors = @[(id)[[UIColor wikiShadowColor] CGColor], (id)[[UIColor clearColor] CGColor]];
[self.layer insertSublayer:gradient atIndex:0];

Upvotes: 1

Views: 482

Answers (1)

David Brunow
David Brunow

Reputation: 1299

I've used layer.shadow successfully:

[setAlarmView.layer setShadowColor:[UIColor blackColor].CGColor];
[setAlarmView.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
[setAlarmView.layer setShadowRadius:35.0];
[setAlarmView.layer setShadowOpacity:1.0];

You will need to include QuartzCore.h.

Upvotes: 3

Related Questions