有人能解释一下如何只在最后一个单元格上创建一个或两个像素的投影吗(换句话说,我不希望整个表格 View 周围有阴影,只是底部单元格。什么的图像我在说:
最佳答案
已解决。使用以下代码在您的 UITableViewCell
底部生成一个非常漂亮的微妙阴影。 .让它看起来像是稍微凸出页面:)
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];
此外,不要忘记将其放在 .m 文件的顶部 #import <QuartzCore/QuartzCore.h>
关于cocoa-touch - 为 UITableView 创建阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17758164/