UITableViewCell的一致背景

时间:2012-02-22 06:55:52

标签: iphone uitableview

我已将半透明图像应用于我的UITableViewCell.contentView。每当我添加自定义accessoryView时,它都没有正确的背景,如下所示:

enter image description here

这是相关代码:

UITableViewCell *tableViewCell = [[UITableViewCell alloc] init];
[tableViewCell.contentView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-bg.png"]]];
//[tableViewCell.backgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-bg.png"]]];
tableViewCell.textLabel.text = @"Test";

UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
[accessoryButton setBackgroundImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal];
[accessoryButton setFrame:CGRectMake(0, 0, 34, 34)];
tableViewCell.accessoryView = accessoryButton;

我也尝试将背景图片添加到backgroundView而不是contentView,但它根本没有显示。怎么解决这个?感谢

2 个答案:

答案 0 :(得分:1)

在你的UITableViewCell包中一个UIImage对象。将其添加到您的手机上。然后在图像上添加所有其他对象。你可以通过这种方式获得欲望屏幕。

答案 1 :(得分:1)

试试这个: -

UIImageView *imgViewCell = [[UIImageView alloc] init];
        [imgViewCell setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 45.0f)];
        [imgViewCell setImage:[UIImage imageNamed:@"list_bg"]];
        [imgViewCell setBackgroundColor:[UIColor clearColor]];
        [cellView.contentView addSubview:imgViewCell];
        [imgViewCell release];  


             UILabel *nameLbl = [[UILabel alloc]initWithFrame:CGRectMake(10.0f, 2.0f, 200.0f, 40.0f)];

        [nameLbl setFont:[UIFont systemFontOfSize:13.0f]];
             [nameLbl setText:@"Test"];  
        [nameLbl setTextColor:[UIColor blackColor]];
        [nameLbl setBackgroundColor:[UIColor clearColor]];
        [cellView.contentView addSubview:nameLbl];



            UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [accessoryButton setImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal];
            [accessoryButton setFrame:CGRectMake(0, 0, 34, 34)];
            cellView.accessoryView = accessoryButton;

Please use arrow.png background transparent