停止多行表格行中的图像扩展?

发布于 2024-11-18 11:45:12 字数 217 浏览 2 评论 0原文

我在实现允许文本换行的表格行时遇到问题,并且左侧还有一个图像,右侧有一个公开附件。

多行文本很好,但是当有多于一行文本时,imageView 会向右扩展。我希望所有行中的图像大小相同。我尝试将 autoresizingMask 设置为 UIViewAutoresizingNone 但这似乎不起作用..我需要使用 contentView 或 nib 文件吗?

任何帮助/示例代码表示赞赏!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月流歌 2024-11-25 11:45:12

如果所有图像的大小都不同,那么您应该考虑将 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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文