iPhone:How to set background image for tablerow cell?

Posted by user187532 on Stack Overflow See other posts from Stack Overflow or by user187532
Published on 2010-05-25T10:38:51Z Indexed on 2010/05/25 10:41 UTC
Read the original article Hit count: 543

Filed under:

Hello all,

I want to put some background image for TableView row cell. I am using the following code:

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

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

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

cell.contentView.opaque = NO;

cell.backgroundColor = [UIColor clearColor];

cell.backgroundColor = backgroundColor;

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

//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? Note: I'm also setting background image for my TableView as well using the below code:

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. Only thing here is, tableview background image is not being static, when scrolling happening, image is also scrolling.

But i want to know first how to set background image for Tableview row cell?

Thank you.

© Stack Overflow or respective owner

Related posts about iphone