如何在UIImageView下显示子文本

时间:2014-08-25 10:01:58

标签: ios objective-c uitableview uiimageview

我有两个数组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

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

3 个答案:

答案 0 :(得分:0)

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

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);

答案 1 :(得分:0)

试试这个

将单元格样式设置为字幕然后

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

答案 2 :(得分:0)

- (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;
}