Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add shadow to only the bottom and right side of a uiview?

I am thinking about adding drop shadow to the bottom and right side of UIView, but I found all the solutions out there are adding shadows for four sides a view. Is there a way to work around that?

like image 980
tom Avatar asked Nov 29 '22 14:11

tom


1 Answers

You can use CAGradientLayer like so,

CAGradientLayer *shadow = [CAGradientLayer layer];
shadow.frame = CGRectMake(-10, 0, 10, myView.frame.size.height);
shadow.startPoint = CGPointMake(1.0, 0.5);
shadow.endPoint = CGPointMake(0, 0.5);
shadow.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.0 alpha:0.4f] CGColor], (id)[[UIColor clearColor] CGColor], nil];
[myView.layer addSublayer:shadow];

You'll have to change the frame to suit your needs. This example displays a shadow along the height of a view on the left. You can also change the start and end point to control the direction of the shadow.

like image 112
edc1591 Avatar answered Dec 09 '22 17:12

edc1591