Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overlap UITableViewCells?

enter image description here

If you look at the screenshot you will notice that each UITableViewCell are 20% overlapped from top portion to the upper tableview cell.

Is there any way we can overlap cells ?

like image 692
Tariq Avatar asked Oct 24 '12 09:10

Tariq


1 Answers

I never tried it, but this kind of logic will work. Remember, you won't get any touch in the overlapped area.

1) Add your subview to cell.contentView, make sure subview height is greater than rowHeight of your tableView.

float overlapHeight  = 10.0;

subView.frame = CGRectMake(0.0, -10.0, 
                  your_subview_width, rowHeight + overlapHeight);

2) Add this code, so that your cell won't clip contents outside its frame

cell.clipsToBounds = NO;
cell.contentView.clipsToBounds = NO;

3) Now your cell's will overlap, but there will be a clip mark around the borders of the cell. To avoid that implement willDisplayCell delegate function

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor clearColor];
}
like image 92
Krishnabhadra Avatar answered Oct 19 '22 23:10

Krishnabhadra