UITableView标头视图覆盖了UITableViewCell的顶部阴影 [英] UITableViewCell top shadow is covered by UITableView header view

查看:85
本文介绍了UITableView标头视图覆盖了UITableViewCell的顶部阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆