【问题标题】:how to display subtext under UIImageViewUIImageView下如何显示subtext
【发布时间】:2014-08-25 10:01:57
【问题描述】:

我有两个数组 1)image_array 和 2)text_array。我知道如何显示图像 和文字。

 cell.imageView.image = [UIImage imageNamed:[text objectAtIndex:indexPath.row]];

    cell.textLabel.text = [arry objectAtIndex:indexPath.row];   

它看起来像

image1     text1
image2     text2
image3     text3
|
|
image7     text7

但我需要喜欢

    image1
    text1

    image2
    text2

|
|
    image7
    text7

请给我任何想法。谢谢高级。

【问题讨论】:

  • 在这种情况下使用自定义表格单元格,它会给你更多的控制
  • 您需要使用可在此处找到的自定义表格单元格,stackoverflow.com/questions/19148582/custom-table-view-cell
  • 是的!自定义单元格可以轻松解决问题。
  • 嘿@ios 开始检查我的答案。,,
  • @channi 感谢重播

标签: ios objective-c uitableview uiimageview


【解决方案1】:

如何创建自定义单元格并设置其图像视图和标签框架属性?

cell.imageView.frame = CGRectMake(XORIG, 0, WI, HI);
cell.textLabel.frame = CGRectMake(XORIG, cell.imageView.frame.origin.y + cell.imageView.frame.size.height, WL, HL);

【讨论】:

    【解决方案2】:

    试试这个

    将单元格样式设置为副标题,然后

    cell.imageView.image = [UIImage imageNamed:[text objectAtIndex:indexPath.row]];
    cell.detailTextLabel.text = = [arry objectAtIndex:indexPath.row]; 
    

    【讨论】:

      【解决方案3】:
      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          NSString *CellIdentifier = [NSString stringWithFormat:@"cell %d",indexPath.row];
      
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      
          cell = nil;
      
          if (cell == nil)
          {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      
              UIImageView *myimagview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
              myimagview.image = [UIImage imageNamed:@""];
              [cell.contentView addSubview:myimagview];
              [myimagview release];
      
      
              UILabel *lbl=[[UILabel alloc]init];
              lbl.frame=CGRectMake(10,60, 250, 20);
              lbl.backgroundColor=[UIColor clearColor];
              lbl.font = [UIFont fontWithName:@"ArialMT" size:14];
              lbl.textColor = [UIColor grayColor];
              lbl.text=@"";
              [cell.contentView addSubview:lbl];
              [lbl release];
      
      
              cell.selectionStyle = UITableViewCellSeparatorStyleNone;
      
          }
          return cell;
      }
      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          return 90;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-24
        • 2011-06-12
        • 2015-10-22
        • 1970-01-01
        相关资源
        最近更新 更多