Creating a dropshadow for UITableView

不羁的心 提交于 2019-12-07 17:40:49

问题


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:


回答1:


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>




回答2:


You could, in tableView:cellForIndexPath: set the cell's background image to one that includes the rounded corners with the shadow.



来源:https://stackoverflow.com/questions/17758164/creating-a-dropshadow-for-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!