UITableView标头视图覆盖了UITableViewCell的顶部阴影 [英] UITableViewCell top shadow is covered by UITableView header view
问题描述
我有一个带有自定义HeaderView的UITableView(通过情节提要添加).我想在表格视图的第一个单元格上放一个阴影.不幸的是,标题视图覆盖了阴影.
I have a UITableView with a custom HeaderView (added via storyboard). I want to put a drop shadow on the first cell in the table view. Unfortunately, the header view covers the shadow.
我在cellForRowAtIndexPath中用以下方法制作阴影:
I am making the shadow in cellForRowAtIndexPath with:
[cell setClipsToBounds:NO];
[cell.layer setMasksToBounds:NO];
[cell.layer setShadowOffset:CGSizeMake(0, 2)];
[cell.layer setShadowColor:[[UIColor blackColor] CGColor]];
[cell.layer setShadowRadius:4.0];
[cell.layer setShadowOpacity:1.0];
[cell.layer setZPosition:10.0];
如果将标题视图的隐藏状态设置为是",则会出现阴影.如果标题可见,则它覆盖了我的阴影.我需要将阴影显示在标题视图的前面.
The shadow appears if I set the hidden state of the header view to YES. If the header if visible, it covers my shadow. I need the shadow to display in front of the header view.
我尝试过:
[self.tableView sendSubviewToBack:self.headerView];
哪个无效.
完成此操作的正确方法是什么?谢谢!
What's the correct way to accomplish this? Thanks!
推荐答案
将标头视图的zPosition
设置为否对我有用:
Setting the header view's zPosition
to negative works for me:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.tableHeaderView.layer.zPosition = -1;
}
我不需要修改视图顺序或设置单元格的zPosition
.
I didn't need to modify view ordering or set the zPosition
of cells.
这篇关于UITableView标头视图覆盖了UITableViewCell的顶部阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!