从加载URL图像转换成一个UIImage,然后加入这些图像到一个UITableViewCell的UIImageView,像下面的代码。 我不知道的图像尺寸,但需要迫使他们是tableviewcell图像的40×40。 这些图像跟上UITableView的不同宽度的装载。
通读到UIImage的大小/缩放相关的其他职位,但这些解决方案并不为我工作。 我想这是因为我使用的包含在UITableViewCell中VS创造我自己的UIImageView的UIImageView的。
下面的代码>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] init];
ItemForSale *item = [listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = item.name;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont systemFontOfSize:14];
NSURL *url = [NSURL URLWithString: item.imgPath];
UIImage *thumbnail = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
if (thumbnail == nil) {
thumbnail = [UIImage imageNamed:@"noimage.png"] ;
}
cell.imageView.image = thumbnail;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.frame = CGRectMake(0, 0, 40, 40);
cell.imageView.autoresizingMask = UIViewAutoresizingNone;
cell.imageView.clipsToBounds = YES;
return cell;
}
我已经尝试设定内容模式(尝试都aspectfill和方面配合),试图复位帧,设定autoresizingmask,clipTobound。 这一切没有改变的事情。