您可以根据下载的图片设置UIImageView 的大小,但它会看起来很糟糕。
所以我建议你把你所有的图片都制作成相同的大小,这样看起来会很好看
您可以使用它来制作相同大小的所有图像。
+ (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;
}
但是,如果您真的想显示具有不同行大小的表格,那么请在运行时更改您的行大小
当您将获得图像时,将您的图像保存在字典中,键值为行的 indexPath。
[tableImageDict setObject:image forKey:[NSString stringWithFormat:@"%i,%i",indexPath.row,indexPath.section]];
然后重新加载表格行。
[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;
}
}