【问题标题】:UITableView with drop shadow带有阴影的 UITableView
【发布时间】:2015-10-29 13:08:38
【问题描述】:
我知道如何在UIViews 周围添加阴影,甚至在bounds 视图发生变化时为其设置动画。但是,我遇到了一个看起来有点棘手的观点。 UITableView
在该视图周围添加阴影非常简单,甚至可以通过以下示例进行:Adding drop shadow to UITableView
它运作良好。但是我的问题是我需要阴影绕过UITableView 中的最后一个cell 而不是bounds。因此,顶部、侧面和底部将是UITableView 中的最后一个单元格。
思考它的工作原理让我相信有更好的解决方案。也许如果我能够根据单元格的数量调整UitableViews 框架?然而,细胞是动态的,直到运行时我才知道它们的高度。
任何建议将不胜感激。
谢谢!
【问题讨论】:
标签:
ios
objective-c
uitableview
【解决方案1】:
类似...
- (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;
}
}
【解决方案2】:
只有一个选项可以满足您的要求:
1) 为top, left and right 的UITableView 添加阴影。
2) 为bottom 的last UITableViewCell 添加阴影。为此,您可能需要增加 UITableView 的最后一个单元格的高度;