每个部分是否总是相同的大小?如果是这样,为什么不将 UITableViewCell 子类化以绘制包含投影的类似笔记本的项目?
您还可以在 UITableView 上添加一个透明的 UIImageView 以获取暗角。
编辑:
这个效果有点棘手,你要看看如何使用 UIBezierPaths (http://developer.apple.com/library/IOS/#documentation/UIKit/Reference/UIBezierPath_class/Reference/Reference .html)。
顶部可以是图像(环和标签效果)。然后,您可以在 drawRect 函数中绘制单元格的其余部分。 (这比在 UITableViewCell 中很重要的 layer 中使用阴影属性更有效)。
您需要覆盖您的 UITableViewCell 类并实现自定义 drawRect: 函数。
这里有一些代码可以帮助您入门:
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
/* Draw top image here */
//now draw the background of the cell.
UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 320, 50)];
[[UIColor grayColor] set];
[path1 fill];
UIBezierPath *path2 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 52, 320, 50)];
[[UIColor whiteColor] set];
[path2 fill];
UIBezierPath *path3 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 104, 320, 50)];
[[UIColor grayColor] set];
[path3 fill];
UIBezierPath *path4 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 156, 320, 50)];
[[UIColor whiteColor] set];
[path4 fill];
//and so on...
//Let's draw the shadow behind the last portion of the cell.
UIBezierPath *shadow = [UIBezierPath bezierPathWithRect:CGRectMake(0, 208, 320, 52)];
[[UIColor darkGrayColor] set];
[shadow fill];
//Finally, here's the last cell with a curved bottom
UIBezierPath *path5 = [UIBezierPath bezierPath];
[path5 moveToPoint:CGPointMake(0, 208)];
[path5 addLineToPoint:CGPointMake(320, 208)];
[path5 addLineToPoint:CGPointMake(320, 258)];
[path5 addCurveToPoint:CGPointMake(0, 258) controlPoint1:CGPointMake(160, 254) controlPoint2:CGPointMake(160, 254)];
[[UIColor grayColor] set];
[path5 fill];
}
代码不是完全拖放,您仍然需要添加白线,修复一些大小,并将最后一个单元格和阴影调整到恰到好处。但这应该足以让您入门。
干杯!