2013-04-05 29 views
0

我有我的tableView。但我有一些圖像在tableViewCell中的問題。背景顏色只顯示在左右角落,但在所有背景的中間顏色顯示我的tableView。當我在我的表改變背景顏色也變了顏色,我tableViewCell中間...如何在tableViewCell中製作背景圖片

我的鱈魚在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但沒有。

+0

請參閱http://stackoverflow.com/questions/6329832/uitableview-cell-with-background-image – 2013-04-05 08:26:34

+0

發佈您的cellForRowAtIndexPath方法代碼。 – Balu 2013-04-05 08:51:46

+0

感謝這一切工作! – 2013-04-05 09:21:03

回答

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