小秋的家

home

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks
最好的方式应该是通过cell.backgroundView来改变cell的背景。按照文档说明,backgroundView始终处于 cell的最下层,所以,将cell里的其它subview背景设为[UIColor clearColor],以cell.backgroundView作为统一的背景,应该是最好的方式。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
static NSString *cellIdentifier = @"CellIdentifier";
 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] autorelease];
}
 
cell.textLabel.text = [NSString stringWithFormat:@"Line: %d", indexPath.row];
cell.textLabel.backgroundColor = [UIColor clearColor];
 
UIView *backgrdView = [[UIView alloc] initWithFrame:cell.frame];
backgrdView.backgroundColor = [UIColor blueColor];
cell.backgroundView = backgrdView;
[backgrdView release];
 
return cell;
}
posted on 2011-10-24 11:28 棋剑小秋 阅读(3358) 评论(0)  编辑  收藏 所属分类: iPhone

只有注册用户登录后才能发表评论。


网站导航: