Question

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.

Was it helpful?

Solution 2

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];

OTHER TIPS

It is probably because you set the frame to CGRectZero.

The zero rectangle is equivalent to CGRectMake(0,0,0,0).

A shadow of a zero rect (x=0, y=0, width=0, height=0) won't show at all.

Try giving it a proper frame size and you will see the difference.

Check out this for ref as well: https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html

In cellForRowAtIndexPath: function:

// drop shadow
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 1.7;
cell.layer.shadowColor = [UIColor blackColor].CGColor;
cell.layer.shadowOffset = CGSizeMake(0.0, 0.0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top