代码改变世界

自定义UITableViewCell 的选中背景图片

2012-10-09 10:58  三戒1993  阅读(109)  评论(0)    收藏  举报
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];

    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                         reuseIdentifier:kCellIdentifier] 
                autorelease];

        cell.selectionStyle = UITableViewCellSelectionStyleBlue; //只有设置这个选择类型,后面的selectedBackgroundView才有作用,不然设置none的话就不起作用

        /* Background */
        cell.backgroundView = [[[UIImageView alloc] init] autorelease];
        cell.selectedBackgroundView = [[[UIImageView alloc] init] autorelease];
    }

    cell.backgroundView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"customBackground"]];
    cell.selectedBackgroundView.backgroundColor = [UIColor redColor];

    return cell;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。