开发者

how to display image to background to tableview Cell

I want to display background image on tableview cell... on t开发者_开发技巧hat i need to display my data.

How to do that?

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


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


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>


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


set background image as

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


- (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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜