【问题标题】:How to add image between tableview and cell如何在表格视图和单元格之间添加图像
【发布时间】:2014-02-25 19:52:26
【问题描述】:

如何在表格视图和单元格之间添加图像?我的意思是,这个图像应该在单元格下方但在表格视图下方。我添加了一个图像,但是当滚动更改其位置随单元格变化时它不是恒定的。我想要在表格视图中使用一个恒定图像,我还添加了一个图像 self.view 但是当单元格来时,图像在单元格下方

【问题讨论】:

    标签: uitableview tableview cell tableviewcell


    【解决方案1】:

    您的问题令人困惑。据我了解,您想将图像添加为 UITableview 的背景,并且该图像不会受到表格滚动的影响。

    解决方案:为您的单元格设置清晰的背景颜色,并将您的图像添加为 Tableview 的背景,如下所述。

    在 ViewDidLoad 中添加以下代码

    UIImageView *tempImageView = [[UIImageView alloc] 
                                  initWithImage:[UIImage imageNamed:@"iPhone.jpg"]];
    [tempImageView setFrame:self.tableView.frame];
    self.tableView.backgroundView = tempImageView;
    

    添加如下方法清除UITableViewCell的背景色。

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

    希望这会有所帮助。快乐编码:)

    【讨论】:

    • 是的,稍加改动就可以了,我看起来是“self.tableView.backgroundView = tempImageView;”谢谢@pratik Mistry! UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logoend.png"]]; UIView * logoView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.checkinsTable.frame.size.width, self.checkinsTable.frame.size.height)]; [logoView addSubview:tempImageView]; tempImageView.frame = CGRectMake(55, 100, 50, 50); self.checkinsTable.backgroundView = logoView;