將每個部分始終是相同的大小?如果是這樣,爲什麼不用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