2

I know how to add a shadow around UIViews and even to animate them when the views bounds change. However I've come across a view that is a little more tricky it seems. UITableView

Adding a shadow around this view is easy enough and even going by this example: Adding drop shadow to UITableView It works well. However my problem is that I need the shadow to go around the last cell in the UITableView and not it's bounds. So, top, sides and bottom would be the last cell in the UITableView.

Thinking about how it'd work leaves me to believe there is a better solution. Maybe if I was able to adjust the UitableViews frame based on the number of cells? However the cells are dynamic and I don't know their heights until runtime.

Any suggestions would greatly be appreciated.

Thanks!

Community
  • 1
  • 1
Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99

2 Answers2

1

something like...

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  if (indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1) {
    // last row
    cell.layer.shadowOpacity = 0.5;
    cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
    cell.layer.masksToBounds = NO;
  }
}
André Slotta
  • 13,774
  • 2
  • 22
  • 34
0

Only one option for your requirement :

1) Add shadow for top, left and right of UITableView.

2) Add shadow to bottom of last UITableViewCell. For this you might need to increase height of last cell of UITableView;

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132