2011-08-18 24 views

回答

1

試一試,

UIImageView *backgroundCellImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 80)]; 

    backgroundCellImage.image=[UIImage imageNamed:@"ImageName.png"]; 

[cell.contentView addSubview:backgroundCellImage]; 
[backgroundCellImage release]; 
13

cellForRowAtIndexPath方法Add:

cell.imageView.image = [UIImage imageNamed:@"img.png"]; 

和完蛋了!真的很簡單!

如果您使用的是自定義單元格,那麼您需要將ImageView添加到IB中的自定義單元格中。然後創建,連接和合成一個IBOutlet它和這個代碼添加到cellForRowAtIndexPath方法:

cell.yourImageOutlet.image = [UIImage imageNamed:@"img.png"]; 
4

cellForRowAtIndexPath method只需添加圖像..

cell.imageView.image = yourImage; 
1

要麼你可以通過添加的UIImageView到所需的位置設置它的框架...

UIImageView *postImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 34, 300, 225)]; 
    postImage.image = [UIImage imageWithData:data]; 
    [postImage setContentMode:UIViewContentModeScaleAspectFill]; 
    postImage.clipsToBounds = YES; 
    [cell addSubview:postImage]; 
    [postImage release]; 

,或者你可以用下面的代碼也去...

cell.myImageView.image = [UIImage imageNamed:@"image.png"]; 
    cell.imageView.contentMode = UIViewContentModeCenter; 
1

只需使用:

如果您正在使用UITableViewCellStyleDefault那麼你並不需要定製的tableviewcells的外觀。

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

    static NSString *CellIdentifier = @"Cell"; 

    // Configure the cell... 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

cell.imageView.image=[UIImage imageNamed:@"ImageName.png"]; 
[email protected]"Text"; 
return cell; 
} 
+0

是圖像查看背景圖像或左側的圖標? – OMGPOP