Jayr Parro

Adding Drop Shadow Effect in a View

A simple implementation of adding a drop shadow effect in a view instead of using “extra” shadow images.

.h file:

1
\#import <QuartzCore/QuartzCore.h>;

.m file:

1
2
3
4
5
6
7
 // add drop shadow
  self.tempView.layer.masksToBounds = NO;
  self.tempView.layer.shadowOffset = CGSizeMake(-10, 10);
  self.tempView.layer.cornerRadius = 10; // round corner
  self.tempView.layer.shadowRadius = 5;
  self.tempView.layer.shadowOpacity = 0.5;
  self.tempView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.tempView.bounds].CGPath; // drawing optimization

Initial View:

Output View:

You can download the code here.

Happy Coding! :)

Comments