如何在tableViewCell中创建背景图像

时间:2013-04-05 08:17:36

标签: ios tableview tableviewcell

我有我的tableView。但我对tableViewCell中的图像有一些问题。背景颜色仅显示在左侧和右侧角落,但中间颜色显示在我的tableView的所有背景中。当我改变表格中的背景颜色时,我在tableViewCell中间也改变了颜色......

我的cod在tableViewCell中添加图片: 何时会推......

cell.backgroundView = [[[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"noselected.png"]stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];

并推了推。推出显示的okey。

cell.selectedBackgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"yesselected.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];

另外:我尝试了UIColour cleareColor但没有。

1 个答案:

答案 0 :(得分:0)

试试这个......

如果您只想为每个单元格显示一个图像。

   cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"name_of_the_image_AND_no_need_to write_extension"]];

如果要为不同的单元格显示不同的图像

首先创建一个图像数组,以保存您需要在单元格中显示的所有图像..

 imgArr = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"image1"],
                                          [UIImage imageNamed:@"image2"],
                                          [UIImage imageNamed:@"image3"],
                                          nil];

然后,在 cellForRowAtIndexPath 方法

cell.backgroundView = [[UIImageView alloc]initWithImage:[imgArr objectAtIndex:indexPath.row]];
相关问题