根据下载的图像高度调整表格单元格的高度 [英] Resize the Table cell height as per downloaded image height

查看:96
本文介绍了根据下载的图像高度调整表格单元格的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时获取图片的网址,我想下载&在表格中显示这些图像。图像将以异步方式下载。更重要的是,我希望以实际尺寸显示所有这些图像。

I am getting the image's URL at run time and I want to download & display these images in a table. Images are going to be download asynchronously. What is more important is that I want to display all these images with their actual sizes.

请帮助我。在此先感谢:)

Kindly help me. Thanks in advance:)

推荐答案

您可以将 UIImageView 大小设为每下载图片,但会给人不好看

You can make your UIImageView size as per downloading image but it will give bad look.

所以我建议你把你所有的图像都做成相同尺寸,这样看起来就像是优惠和甜蜜

So i suggest you to make all your image of same size , so it will be look fine and sweet

您可以使用它来制作相同尺寸的所有图像。

you can use this to make all your image of same size.

+ (UIImage *)imageScaledToSizeWithImage:(UIImage *)imagewww andsizeee:(CGSize)size
{
    //avoid redundant drawing
    if (CGSizeEqualToSize(imagewww.size, size))
    {
        return imagewww;
    }

    //create drawing context
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);

    //draw
    [imagewww drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)];

    //capture resultant image
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //return image
    return image;
}

但是如果你真的想要显示不同行大小的表格,那么请更改你的运行时的行大小

But if you really want to show table with different row size then make change your row size on run time

当你得到图像然后将你的图像保存在字典中,键值是行的indexPath。

when you will get image then save your image in dictionary with key value is indexPath of row.

[tableImageDict setObject:image forKey:[NSString stringWithFormat:@"%i,%i",indexPath.row,indexPath.section]];

然后重新加载你的表格行。

and then reload your table row.

[table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                     withRowAnimation:UITableViewRowAnimationNone];

它会改变你的行高

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage *image = (UIImage *)[tableImageDict objectForKey:
                                 [NSString stringWithFormat:@"%i,%i",
                                  indexPath.row,indexPath.section]];


    if (image != nil)
    {
        return image.size.height;
    }
    else{
        return 44.0;
    }
}

这篇关于根据下载的图像高度调整表格单元格的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆