質問

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!

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top