如何将图像显示到tableview Cell的背景

时间:2010-10-19 06:41:18

标签: iphone

我想在tableview单元格上显示背景图片...我需要显示我的数据。

怎么做?

@thanks提前......任何精通帮助我。

5 个答案:

答案 0 :(得分:0)

在单元格上设置一个类,然后使用CSS将背景图像放入,如下所示:

<table class="myTable">
 <tr>
   <td class="myCell"></td>
 </tr>
</table>

<style>
  .myCell {
    background: url(my_image.gif)
  } 
</style>

答案 1 :(得分:0)

一种方法是修改UITableViewCell的contentView。例如:

//Add custom objects to the cell in here!
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpg"]];

imageView.center = CGPointMake(310, 48);
[cell.contentView addSubview:imageView];
cell.textLabel.text=@"test";

答案 2 :(得分:0)

将背景图像设置为

   UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourImage.png"]];
    [cell setBackgroundView:img];

答案 3 :(得分:0)

您是否想要为您的桌子或UITableView中的单个单元格设置背景图像 如果用于设置背景图像,请执行以下操作:


UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background.png" ofType:nil]];
UIColor *bgColor = [[UIColor alloc] initWithPatternImage:bgImage];  self.view.backgroundColor = bgColor;    
[tableName setBackgroundColor:[UIColor clearColor]];

其中tableName是UItableView的名称

如果要为UITableView单元格设置背景图像,请执行以下操作:


cell.backgroundColor = [UIColor clearColor];
UIImageView *cellBG_tap = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.png" ofType:nil]]];
cell.backgroundView = cellBG_tap; 
[cellBG_tap release];

答案 4 :(得分:0)

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.textLabel.font =[UIFont systemFontOfSize:20.0];
    cell.detailTextLabel.textColor=[UIColor whiteColor];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.imageView.image = [UIImage imageNamed:@"Square.gif"];

}
表视图数据源中的

cellForRowAtIndexPath
if (indexPath.row%2==0) {
UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image..."]];
cell.backgroundView=img;
[img release];

我用它来工作.... @all感谢人们贡献你的知识