Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions GroupedTableViewWithShadows/UITableViewCell+CellShadows.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ @implementation UITableViewCell (CellShadows)
- (void)addShadowToCellInTableView:(UITableView *)tableView
atIndexPath:(NSIndexPath *)indexPath
{
BOOL isFirstRow = !indexPath.row;
BOOL isLastRow = (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1);
BOOL SingleRow = [tableView numberOfRowsInSection:indexPath.section] == 1;
BOOL isFirstRow = !indexPath.row && !SingleRow;
BOOL isLastRow = (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) && !SingleRow;

// the shadow rect determines the area in which the shadow gets drawn
CGRect shadowRect = CGRectInset(self.backgroundView.bounds, 0, -10);
if(isFirstRow)
shadowRect.origin.y += 10;
else if(isLastRow)
shadowRect.size.height -= 10;

else if (SingleRow){
shadowRect.origin.y += 10;
shadowRect.size.height -= 20;
}
// the mask rect ensures that the shadow doesn't bleed into other table cells
CGRect maskRect = CGRectInset(self.backgroundView.bounds, -20, 0);
if(isFirstRow) {
Expand All @@ -30,7 +34,11 @@ - (void)addShadowToCellInTableView:(UITableView *)tableView
}
else if(isLastRow)
maskRect.size.height += 10;

else if (SingleRow){
maskRect.origin.y -= 10;
maskRect.size.height += 20;
}

// now configure the background view layer with the shadow
CALayer *layer = self.backgroundView.layer;
layer.shadowColor = [UIColor redColor].CGColor;
Expand Down