Matt Gallagher做了一个很好的演练:Adding shadow effects to UITableView using CAGradientLayer。
它使用绘制CAGradientLayer作为单元格的背景视图的自定义UIView子类。建立视图的代码trivial-
在GradientView UIView子类:
CAGradientLayer *gradientLayer = (CAGradientLayer *)self.layer;
gradientLayer.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0].CGColor,
(id)[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.0].CGColor, nil];
self.backgroundColor = [UIColor clearColor];
在的UITableViewController的cellForRowAtIndexPath:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [{ Set up your cell}];
cell.backgroundView = [[[GradientView alloc] init] autorelease];
}
当然,也有一些并发症,但在Matt的网站上有一个很好的,简单的示例应用程序。
只是一个nit:细胞在UITableView
,而不是控制器。