tags:

views:

38

answers:

5

I want to display background image on tableview cell... on that i need to display my data.

How to do that?

@thanks in advance... Any proficient help me out.

A: 

set a class on the cell, then use CSS to put the background image in, like below:

<table class="myTable">
 <tr>
   <td class="myCell"></td>
 </tr>
</table>

<style>
  .myCell {
    background: url(my_image.gif)
  } 
</style>
Anatoly G
Pretty sure @kiran meant using a UITableViewCell, not web page.
Jordan
This question is tagged under "iPhone", not HTML or CSS.
Jacob Relkin
my bad. should have red more carefully.
Anatoly G
displayed image on tableviewcell ... but my data is not visible ... i thought to set Opacity for image view... Is this is a correct way to do ....
kiran kumar
@ anatoly its my bad... i need to put it very clearly ...
kiran kumar
A: 

One way is to modify the UITableViewCell's contentView. For example:

//Add custom objects to the cell in here!
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpg"]];

imageView.center = CGPointMake(310, 48);
[cell.contentView addSubview:imageView];
cell.textLabel.text=@"test";
Jordan
A: 

set background image as

   UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourImage.png"]];
    [cell setBackgroundView:img];
Gyani
A: 

Do u want set background image for your table or for individual cell in UITableView If it is for setting the background image then do the following:

UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background.png" ofType:nil]]; UIColor *bgColor = [[UIColor alloc] initWithPatternImage:bgImage]; self.view.backgroundColor = bgColor;
[tableName setBackgroundColor:[UIColor clearColor]];

where tableName is the name of your UItableView

If you want to set background image for UITableView cell then do the following:

cell.backgroundColor = [UIColor clearColor]; UIImageView *cellBG_tap = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.png" ofType:nil]]]; cell.backgroundView = cellBG_tap; [cellBG_tap release];

Swapna
Also set the cell.backgroundColor = [UIColor clearColor] before setting backgroundColor for the cell
Swapna
@ swapna Thanks -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ cell.textLabel.font =[UIFont systemFontOfSize:20.0]; cell.detailTextLabel.textColor=[UIColor whiteColor]; cell.detailTextLabel.font = [UIFont systemFontOfSize:15.0]; cell.textLabel.backgroundColor = [UIColor clearColor]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; cell.imageView.image = [UIImage imageNamed:@"Sapphire Square.gif"];} -used above code which worked .thanks to all
kiran kumar
A: 
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.textLabel.font =[UIFont systemFontOfSize:20.0];
    cell.detailTextLabel.textColor=[UIColor whiteColor];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.imageView.image = [UIImage imageNamed:@"Square.gif"];

}

in table view data source

cellForRowAtIndexPath
if (indexPath.row%2==0) {
UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image..."]];
cell.backgroundView=img;
[img release];

I used this its working .... @all Thanks people for contributing your knowledge

kiran kumar