2013-03-12 32 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