2013-03-12 34 views
0

我有一个小问题。我想在UITableViewCell(在中间)显示多个(数量是动态的)UIImage。IOS集中UIImages在连续

我该怎么做(UIImages是以编程方式生成的)?

非常感谢!

回答

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if(cell == nil) 
     { 
      cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 


      self.imgThings = [[UIImageView alloc] init]; 
      // imgThings.backgroundColor= [UIColor magentaColor]; 
      [self.imgThings setImage: [UIImage imageNamed:@"image.png"]]; 
      self.imgThings.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2); 
      [cell.contentView addSubview:self.imgThings]; 
     } 
    return cell; 

} 

上面是只有一个图像的简单示例,您还可以通过更改图像的名称将其设置为多个图像。

+0

嗨,谢谢你的片段。这几乎是我需要的。但在我的例子中,我有多个图像不仅在一行中。例如,这是一行:(UIImage)| (UIImage)| (UIImage) - (DetailEnclosure);就像一个有一行和多列的表一样。 – Bene 2013-03-12 13:45:40

+2

@Bene如果有超过3张图片怎么办? – Anupdas 2013-03-12 15:52:33

+2

@Bene如果您的目标是iOS 6.0及以上版本,现在可能是学习自动布局的好时机。您可以将规则设置为具有最小填充和规则,以使所有imageView具有与单元格的contentView相同的高度和宽度。 – Anupdas 2013-03-12 15:55:21