修改UITableView背景图片

之前直接继承了一个UITableViewController ,发现怎么设置都无法改变uitableview的背景图片,直接设置backgroundcolor 属性得到的效果是每个tablecell的颜色是重复的,而不是改变整个tableview的背景。

        上网查后发现,改变tableview的背景图片的方法是在tableview的下面加个UIImageView,把要添加的背景图片加到UIImageView上面去,然后把UITableView的背景颜色改为clearcolor即可。所以只好删掉原来的UITableViewController,重新建一个UIViewController,然后手动添加UIImageView和UITableView。


示例代码如下:

- (id)init
{
    self = [super init];
    if (self) {
        // Custom initialization
      
        CGRect   frame = self.view.bounds;            
        UIImageView *background = [[UIImageView alloc]initWithFrame:frame];
        background.image = [UIImage imageNamed:BGIMAGE];
        [self.view addSubview:background];
        [background release];
        
        self.tableView = [[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.backgroundColor = [UIColor clearColor];
        self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        [self.view addSubview:self.tableView];
    }
    return self;
}

你可能感兴趣的:(initialization)