简体   繁体   English

iPhone:如何设置表格单元格的背景图像?

[英]iPhone:How to set background image for tablerow cell?

I want to put some background image for TableView row cell. 我想为TableView行单元格放置一些背景图像。 I am using the following code: 我正在使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

..................... .....................

................... ...................
UIImage * backgroundImage = [UIImage imageNamed:@"cell.png"]; UIImage * backgroundImage = [UIImage imageNamed:@“ cell.png”]; UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage]; UIColor * backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];
cell.opaque = NO; cell.opaque = NO;

cell.contentView.opaque = NO; cell.contentView.opaque = NO;

cell.backgroundColor = [UIColor clearColor]; cell.backgroundColor = [UIColor clearColor];

cell.backgroundColor = backgroundColor; cell.backgroundColor = backgroundColor;

//cell.contentView.backgroundColor = [UIColor clearColor]; //cell.contentView.backgroundColor = [UIColor clearColor];

//cell.contentView.backgroundColor = backgroundColor; //cell.contentView.backgroundColor = backgroundColor;

} }

But it is not giving the background image properly. 但这不能正确提供背景图像。 Could someone guide me what is the proper ways of setting background image for a tableview row? 有人可以指导我为tableview行设置背景图像的正确方法是什么? Note: I'm also setting background image for my TableView as well using the below code: 注意:我也使用以下代码为TableView设置背景图像:

UIImage * backgroundImage = [UIImage imageNamed:@"Tablebackground.png"];
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];
self.myTableView.backgroundColor = [UIColor clearColor];
self.myTableView.alpha = 0.9;
self.myTableView.backgroundColor = backgroundColor;

I don't observe any problem for tableview background. 我没有发现tableview背景有任何问题。 Only thing here is, tableview background image is not being static, when scrolling happening, image is also scrolling. 这里唯一的事情是,tableview背景图像不是静态的,滚动发生时,图像也在滚动。

But i want to know first how to set background image for Tableview row cell? 但是我想首先知道如何为Tableview行单元格设置背景图像?

Thank you. 谢谢。

这是迄今为止我阅读过的有关UITableView定制的最佳教程: http : //cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM