URLからの画像をuiimageに読み込んだ後、これらの画像を下のコードのようにuitableviewcell uiimageviewに追加します。画像のサイズはわかりませんが、テーブルビューの画像で40x40にする必要があります。画像は、uitableviewでさまざまな幅で読み込みを続けます。URLからUIImageを読み込んだとき、UITableViewCellでUIImageViewのサイズを設定しますか?
uiimageサイジング/スケーリングに関連する他の記事を読んでください。しかし、それらの解決策は私のためには機能しません。私はuuitableviewcellに含まれているuiimageviewを使用しているので自分自身のuiimageviewを作成していると思っています。
は、ここで私は、コンテンツモード(aspectfillとアスペクトフィット感の両方を試してみました)を設定しようとしたコード>
- (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;
}
だ、autoresizingmask、clipToboundを設定し、フレームをリセットしてみました。それを変えたものはありませんでした。
私はカスタムuiimageviewでこれを試しましたが、うまくいきます。 uitableviewcellに含まれているuimageviewで何かでなければならない – Augie