【问题标题】:UITableView image on the left hand side [duplicate]左侧的 UITableView 图像[重复]
【发布时间】:2011-08-18 04:21:55
【问题描述】:

可能重复:
adding images to UItableView

我想在左侧的 UITableView 中添加图片如何添加?

【问题讨论】:

    标签: iphone objective-c xcode


    【解决方案1】:

    cellForRowAtIndexPath方法中添加:

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

    就是这样!真的很简单!

    如果您使用的是自定义单元格,那么您需要将 ImageView 添加到 IB 中的自定义单元格中。然后为其创建、连接和合成一个 IBOutlet 并将此代码添加到 cellForRowAtIndexPath 方法中:

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

    【讨论】:

      【解决方案2】:

      只需将图片添加到cellForRowAtIndexPath method..

       cell.imageView.image = yourImage;
      

      【讨论】:

        【解决方案3】:

        试试这个,

        UIImageView *backgroundCellImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 80)];
        
            backgroundCellImage.image=[UIImage imageNamed:@"ImageName.png"];
        
        [cell.contentView addSubview:backgroundCellImage];
        [backgroundCellImage release];
        

        【讨论】:

          【解决方案4】:

          您可以通过设置 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;
          

          【讨论】:

            【解决方案5】:

            只需使用:

            如果您使用的是 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"];
            cell.textLabel.text=@"Text";
            return cell;
            } 
            

            【讨论】:

            • 图片视图是背景图片还是左边的图标?
            猜你喜欢
            • 1970-01-01
            • 2021-01-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-08-28
            • 1970-01-01
            • 2021-09-27
            • 1970-01-01
            相关资源
            最近更新 更多