简体   繁体   English

带有阴影的 UITableView

[英]UITableView with drop shadow

I know how to add a shadow around UIViews and even to animate them when the views bounds change.我知道如何在UIViews周围添加阴影,甚至在视图bounds改变时为它们设置动画。 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.在此视图周围添加阴影很容易,甚至可以通过以下示例进行操作: 向 UITableView 添加阴影效果很好。 However my problem is that I need the shadow to go around the last cell in the UITableView and not it's bounds .但是我的问题是我需要阴影围绕UITableView的最后一个cell而不是它的bounds So, top, sides and bottom would be the last cell in the UITableView .因此,顶部、侧面和底部将是UITableView的最后一个单元格。

Thinking about how it'd work leaves me to believe there is a better solution.考虑它是如何工作的,我相信有更好的解决方案。 Maybe if I was able to adjust the UitableView s frame based on the number of cells?也许如果我能够根据单元格的数量调整UitableView的框架? However the cells are dynamic and I don't know their heights until runtime.然而,单元格是动态的,直到运行时我才知道它们的高度。

Any suggestions would greatly be appreciated.任何建议将不胜感激。

Thanks!谢谢!

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;
  }
}

Only one option for your requirement :您的要求只有一种选择:

1) Add shadow for top, left and right of UITableView . 1) 为UITableView top, left and right添加阴影。

2) Add shadow to bottom of last UITableViewCell . 2) 在last UITableViewCell bottom添加阴影。 For this you might need to increase height of last cell of UITableView;为此,您可能需要增加 UITableView 的最后一个单元格的高度;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM