0

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;
Rahul Jiresal
  • 1,006
  • 13
  • 24
  • possible duplicate of [UIView with rounded corners and drop shadow?](http://stackoverflow.com/questions/4754392/uiview-with-rounded-corners-and-drop-shadow) – Desdenova Feb 28 '14 at 08:22
  • Try this code.. http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview – RAJA Feb 28 '14 at 08:26
  • Wow, I don't know why someone voted this down. Totally legit question. (I voted +1 to bring it up to 0.) Do you absolutely need masksToBounds = YES? If you need it for another element, then try putting the view that requires masksToBounds within another view and adding the shadow to the bottom view. – Lyndsey Scott Feb 28 '14 at 08:31

2 Answers2

3

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.

Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • This is what I ended up doing — Added a parent view of the shadow colour, and made the current view 3 pixels smaller and added to that parent view. It looks the way I wanted it. Thanks! – Rahul Jiresal Feb 28 '14 at 08:44
0

This tutorial link may help you..

http://nscookbook.com/2013/01/ios-programming-recipe-10-adding-a-shadow-to-uiview/

How do I draw a shadow under a UIView?

Community
  • 1
  • 1
RAJA
  • 1,214
  • 10
  • 13