0

Here is my problem. I have embed inside a UIVIew a UITableView with 3 rows. The UITableView should show a drop-shadow and should have rounded corners. To do this I created the method "setShadowsForViews" which I call in ViewDidLoad.

- (void) setShadowsForViews: (UIView *)view{
    view.backgroundColor = COLOR_WHITE;
    view.layer.cornerRadius = 8.0;
    view.layer.shadowColor = UIColor.blackColor.CGColor;
    view.layer.shadowOpacity = 0.4;
    view.layer.shadowRadius = 5;
    view.layer.shadowOffset = CGSizeMake(5, 5);
}

Also inside ViewDidLoad, I've inserted this piece of code:

self.tableView.clipsToBounds = NO;
self.tableView.layer.masksToBounds = NO;

So, now the shadow is visible outside the TableView.

The problem is that by doing this, the corners are not rounded, but the TableView takes the shape of the underlying content (with sharp corners). How can I fix this?

Here is a screenshot:

enter image description here

koen
  • 5,383
  • 7
  • 50
  • 89
  • Make life easy - put the tableview inside another uiview and then you can shape that uiview the way you like. – skaak Mar 31 '21 at 17:48
  • “should show a drop-shadow and should have rounded corners” Nope. You can’t have both. If you clip/mask to the rounded corner, you clip out the shadow. And if you don’t clip, the corners are not rounded. – matt Mar 31 '21 at 22:49
  • 1
    The @skaak answer is the easiest way to solve the problem. Actually, I didn't want to add so many views in order to simplify the project, but But in the end I think I will adopt this solution. – Fabrizio L. Apr 01 '21 at 08:17
  • 1
    Thanks to @matt for clarifying the concepts of clip/mask that made me crazy. Thank you all. – Fabrizio L. Apr 01 '21 at 08:17

0 Answers0