Rahul Jiresal
Rahul Jiresal

Reputation: 1006

View Shadow in iOS

I have achieved a view that looks like this —

enter image description here

But I want the bottom of the view to look like this —

enter image description here

Adding a shadow is not helping because as soon as I do maskToBounds = YES, I get what I have in the first picture. This is the code I have so far

[self.contentView.layer setCornerRadius:3.0f];
UIColor* color = CardBorderColor; // this is a macro that defines the color
[self.contentView.layer setBorderColor:color.CGColor];
[self.contentView.layer setBorderWidth:1.0f];
[self.contentView.layer setShadowColor:color.CGColor];
[self.contentView.layer setShadowOpacity:1.0];
[self.contentView.layer setShadowRadius:3.0];
[self.contentView.layer setShadowOffset:CGSizeMake(1.0, 1.0)];
self.contentView.layer.masksToBounds = YES;

Upvotes: 0

Views: 258

Answers (2)

Lyndsey Scott
Lyndsey Scott

Reputation: 37290

Unfortunately, yes, using masksToBounds will mask out your shadow. If you need to set maskToBounds = YES for another element in that view, then put the view that requires masksToBounds on top of another UIView and adding the shadow to that bottom view.

Upvotes: 3

Related Questions