Samuli Lehtonen
Samuli Lehtonen

Reputation: 3860

Adding a shadow at the edge of the UIView(Picture inside)

So, I am looking for the most practical way to adding a shadow at the edge of UIView like shown in the picture below. I tried some ways that I read but really couldn't make them work as I wanted. It would be nice if someone had an idea how apple does this in their apps.

Picture link(Didn't want to post it directly here as it was pretty big): Example image

Upvotes: 2

Views: 968

Answers (2)

arturdev
arturdev

Reputation: 11039

- (void) configureSlideLayer:(CALayer *)layer
{
    layer.shadowColor = [UIColor blackColor].CGColor;
    layer.shadowOpacity = 1;
    layer.shadowOffset = CGSizeMake(-3, 0);
    layer.shadowRadius = 5;
    layer.masksToBounds = NO;
    layer.shadowPath =[UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
}
...
[self configureSlideLayer:self.view.layer];

source: https://github.com/arturdev/AMSlideMenu

Upvotes: 3

Gavin
Gavin

Reputation: 8200

The following properties deal with shadows on UIViews:

view.layer.shadowOpacity = 0.5;
view.layer.shadowRadius = 25;
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(-3, 0);

That code will make a black shadow at half opacity, with a shadow radius of 25 pixels, and shifted 3 pixels to the left. You'll need to add the following import to the top of the file:

#import <QuartzCore/QuartzCore.h>

You may also need to add the QuartzCore framework to your project if it isn't already.

Upvotes: 3

Related Questions