将每个部分始终是相同的大小?如果是这样,为什么不用UITableViewCell子类来绘制包含阴影的项目?
你也可以在UITableView上添加一个透明的UIImageView来获得黑暗的角落。
编辑:
这种效果是有点棘手,你会想看看如何使用UIBezierPaths(http://developer.apple.com/library/IOS/#documentation/UIKit/参考/ UIBezierPath_class /参考/的reference.html)。
顶部可以是一个图像(环和标签效果)。然后可以在drawRect函数中绘制其余的单元格。 (这比在UITableViewCell中重要的层中使用阴影属性更有效)。
你会想覆盖你的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];
}
的代码是不是很拖放,您仍然需要添加的白线,修正了一些尺寸,并调整最后一个单元格和阴影恰到好处。但它应该足以让你开始。
干杯!
链接不存在。 – Leena