可以爲細胞背景漸變的,在這種情況下,你可能會因爲你用cell.layer不用擔心圓角。 (在您的項目中爲此導入Quartz框架)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (indexPath.row == 0) // first cell
{
// set background gradient
CAGradientLayer *gradient = [[CAGradientLayer alloc] init];
gradient.position = CGPointMake(0, 0);
gradient.frame = cell.frame;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.207 green:0.207 blue:0.207 alpha:1.0] CGColor], (id)[[UIColor colorWithRed:0.125 green:0.125 blue:0.125 alpha:1.0] CGColor], nil];
[[cell.layer.sublayers objectAtIndex:0] removeFromSuperlayer];
[cell.layer insertSublayer:gradient atIndex:0];
[gradient release];
}
else if (indexPath.row == 1) // second cell
{
//
// Another gradient
//
}
}
return cell;
}
要變更背景視圖或顏色? – Neo 2012-08-13 05:57:55
不是我想象的顏色。因爲我試圖添加漸變背景。 – tipsywacky 2012-08-13 06:06:57
嘗試cell.backgroundView.clipsToBounds = YES; – 2012-08-13 07:03:00