背景图像UITableView在滚动时更改

时间:2013-12-09 21:25:23

标签: ios objective-c uitableview

我设置了tableView的backgroundImage:

self.tableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Content.png"]];

我设置透明表格的backGroundColor单元格视图:

SBQCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell==nil){
        cell.backgroundColor=[UIColor clearColor];   
    }

当我滚动时,表格视图的backGroundColor会发生变化。

捕获1(无滚动):

Image1

捕获2(使用滚动):

enter image description here

这是我用作背景的图像:

enter image description here

如何将图像背景拉到全表视图?感谢

4 个答案:

答案 0 :(得分:4)

在TableView后面的视图层上创建背景,而不是在TableView本身上,然后在UITableView上设置清晰的背景

...或

设置tableview.backgroundView而不是backgroundColor

答案 1 :(得分:1)

解决:

self.tableView.backgroundView=[[UIImageView alloc] initWithImage:
                                   [UIImage imageNamed:@"ContentBg.png"]];

更多:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.backgroundColor = [UIColor clearColor];

}

滚动时单元格保持透明,表格视图的backGround图像调整大小。

谢谢大家!

答案 2 :(得分:0)

您将背景图像作为图案添加到backgroundColor属性。

也许试试这个:

UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Content.png"]];
[self.tableView setBackgroundView:iv];

请在此处查看 Apple UITableView 类引用:

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/backgroundView

答案 3 :(得分:0)

你有:

if (cell==nil){
        cell.backgroundColor=[UIColor clearColor];   
    }

我认为你的意思是:

if (cell!=nil) {
        cell.backgroundColor=[UIColor clearColor];   
    }
相关问题