【问题标题】:How make background image in tableViewCell如何在 tableViewCell 中制作背景图片
【发布时间】:2013-04-05 08:17:35
【问题描述】:

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

我在 tableViewCell 中添加图像的代码: 什么时候推送...

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

然后推。按下显示好的。

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

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

【问题讨论】:

标签: ios tableview tableviewcell


【解决方案1】:

试试这个...

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

   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]];

【讨论】:

    猜你喜欢
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多