UITableViewCell top shadow is covered by UITableView header view

て烟熏妆下的殇ゞ 提交于 2021-01-27 17:17:39

问题


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.

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.

I have tried:

[self.tableView sendSubviewToBack:self.headerView];

Which has no effect.

What's the correct way to accomplish this? Thanks!


回答1:


Setting the header view's zPosition to negative works for me:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.tableHeaderView.layer.zPosition = -1;
}

I didn't need to modify view ordering or set the zPosition of cells.



来源:https://stackoverflow.com/questions/22305169/uitableviewcell-top-shadow-is-covered-by-uitableview-header-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!