Stop image expanding in multiline table row?

北慕城南 提交于 2019-12-14 03:26:45

问题


I'm having problems implementing a table row that allows text to wrap to multiple lines, and also has an image on the left, and a disclosure accesssory on the right.

The multiline text is fine but the imageView expands to the right when there is more than one line of text. I want images in all rows to be the same size. I've tried setting the autoresizingMask to UIViewAutoresizingNone but this doesn't seem to work.. Do I need to use the contentView, or a nib file?

Any help/example code appreciated!


回答1:


If all off your images are different size then you should think of adding a ImageView as Subview to cell. Keep Labels depending on the Imageview.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;

    UIImageView *cellImage;
    UILabel *label;
    UILabel *detailLabel;

    cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; //Create cell
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];

        cellImage = [[[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 44, 44)] autorelease];


        label = [[[UILabel alloc] initWithFrame:CGRectMake(55, 4, 260, 20)] autorelease];
        label.font = [UIFont boldSystemFontOfSize:15.0];
        label.tag=25;

        detailLabel = [[[UILabel alloc] initWithFrame:CGRectMake(55, 25, 260, 15)] autorelease];
        detailLabel.font = [UIFont systemFontOfSize:13.0];
        detailLabel.tag=30;

        [cell.contentView addSubview:cellImage];
        [cell.contentView addSubview:label];
        [cell.contentView addSubview:detailLabel];
        cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;

    }
    else
    {
        cellImage = (UIImageView *)[cell.contentView viewWithTag:20];
        label = (UILabel *)[cell.contentView viewWithTag:25];
        detailLabel = (UILabel *)[cell.contentView viewWithTag:30];
    }
    cell.image = [arrayContainingImages objectAtIndex:indexPath.row];
    label.text =[arrayContaininglabeltext objectAtIndex:indexPath.row];
    detailLabel.text=[arrayContainingDetailLabelText objectAtIndex:indexPath.row];
    return cell;
}



回答2:


pls see Stop image expanding in multiline table row? #2



来源:https://stackoverflow.com/questions/6569492/stop-image-expanding-in-multiline-table-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!