Search code examples
objective-cuitableviewios5dropshadow

iOS: Table cell footer dropshadow


I have a tableview with only a few rows. So instead of displaying a bunch of blanks I added a blank UIView to the tableview.footer. However I would like the last cell to cast a dropshadow on the UIView. How would I achieve this? Here is my current code.

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *emptyView = [[UIView alloc] initWithFrame:CGRectZero];
    CALayer *layer = [emptyView layer];
    [layer setShadowOffset:CGSizeMake(0, 1)];
    [layer setShadowColor:[[UIColor darkGrayColor] CGColor]];
    [layer setShadowRadius:8.0];
    [layer setShadowOpacity:0.8];
    self.tableView.tableFooterView = emptyView;
}

EDIT: It is adding the UIView to the footer but not creating the dropshadow. I'm not sure the layer is the best approach for this or even correct for this type of thing.


Solution

  • I ended up using

    shadowBackgroundView.layer.shadowOpacity = 0.3; 
    shadowBackgroundView.layer.shadowRadius = 2;
    shadowBackgroundView.layer.shadowColor = [[UIColor blackColor] CGColor];
    shadowBackgroundView.layer.shadowOffset = CGSizeMake(0.0, 1.0);
    CGPathRef shadowPath = [UIBezierPath bezierPathWithRoundedRect: shadowBackgroundView.bounds 
                                                             byRoundingCorners: UIRectCornerAllCorners
                                                                   cornerRadii: CGSizeMake(PageCellBackgroundRadius, PageCellBackgroundRadius)].CGPath;
    shadowBackgroundView.layer.shadowPath = shadowPath;
    shadowBackgroundView.layer.shouldRasterize = YES;
    
    [self addSubview: shadowBackgroundView];