我正在从我的网络服务器加载一组图像,以显示在右侧的单元格中。但是,图像有不同的大小,因此即使显示列表,它们也看起来不一样。无论如何,我可以将图像设置为固定尺寸,如 100 x 80 吗?
我的代码如下:
cell.lotImageView.image = [UIImage imageNamed:@"blankthumbnail.png"];
cell.lotImageView.clipsToBounds = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
//load image from web server
NSString *strURL = [NSString stringWithFormat:@"%@/images/%@", user.url, lotPhoto[row]];
NSURL *url = [[NSURL alloc] initWithString:strURL ];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
dispatch_async(dispatch_get_main_queue(), ^{
// let's make sure the cell is still visible (i.e. hasn't scrolled off the screen)
mainTableCell *cell = (mainTableCell *)[tableView cellForRowAtIndexPath:indexPath];
if (cell)
{
cell.lotImageView.clipsToBounds = YES;
cell.lotImageView.image =image;
}
});
});