0
votes

I have a problem using the following code to set background of UITAbleview. Can I have a alternative images on the cell inside the UITable by using the following code?

e.g. cell 1 using X.png and cell 2 using Y.png?

tableView.opaque = NO; [tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.png"]]]; cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]];

Thanks a lot.

1
Specify what do you want?I am not clear about your question.Emon
Sorry for the unclear question, what i am trying to do is to have a table, inside each cell row can they have different background image? e.g. the first row item is using X.png image then the second row uses Y.png image. Is it possible? ThanksClarence

1 Answers

1
votes

At first take a view in your .h file UIView *newView; declare its property and synhesize it at your .m file

Now in cellForRowAtIndexPath

if(cell==nil){
................
.........
newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
    [cell.contentView addSubview:newView];
................
...............
}
if(indexPath.row == 0){

    newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]];

}
if(indexPath.row == 1){

    newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]];

}
if(indexPath.row == 2){

    newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood.jpg"]];

}

If any further question please knock me.

EDIT:

if any problem still now then check this link http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html