Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a dropshadow for UITableView

Would somebody please explain how to create a one or two pixel drop shadow ONLY on the the very last cell (in other words, I don't want a shadow around the entire tableview, just the bottom cell. An image of what I'm talking about:

enter image description here

like image 219
Apollo Avatar asked Aug 07 '26 18:08

Apollo


1 Answers

Solved. Use the following code to produce a very nice, subtle shadow to the bottom of your UITableViewCell. Makes it look like it's raised slightly out of the page :)

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(3, 49, cell.frame.size.width-26, 3)];/// change size as you need.
        separatorLineView.backgroundColor = shadowColor;// you can also put image here
        UIBezierPath *roundedShadow = [UIBezierPath bezierPathWithRoundedRect:separatorLineView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8.0f, 8.0f)];
        CAShapeLayer *newSeparatorShape = [[CAShapeLayer alloc] init];
         [newSeparatorShape setPath:roundedShadow.CGPath];

        separatorLineView.layer.mask = newSeparatorShape;

        [cell.contentView addSubview:separatorLineView];

Also, don't forget to put this at the top of your .m file #import <QuartzCore/QuartzCore.h>

like image 73
Apollo Avatar answered Aug 11 '26 00:08

Apollo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!