From 2426b428a21d26a0c87b4b98ce8848464eb406ae Mon Sep 17 00:00:00 2001 From: ilia3546 Date: Thu, 16 May 2013 12:54:45 +0400 Subject: [PATCH] Update UITableViewCell+CellShadows.m Add right shadow to Single Rows --- .../UITableViewCell+CellShadows.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/GroupedTableViewWithShadows/UITableViewCell+CellShadows.m b/GroupedTableViewWithShadows/UITableViewCell+CellShadows.m index e0f9dd5..c8bd2e4 100644 --- a/GroupedTableViewWithShadows/UITableViewCell+CellShadows.m +++ b/GroupedTableViewWithShadows/UITableViewCell+CellShadows.m @@ -12,8 +12,9 @@ @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); @@ -21,7 +22,10 @@ - (void)addShadowToCellInTableView:(UITableView *)tableView 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) { @@ -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;