我正在從我的web服務器加載一組圖像以顯示在右側的單元格中。但是,圖像大小不同,因此即使顯示列表,圖像也不會顯示。無論如何,我可以將圖像設置爲像100 x 80這樣的固定大小?xcode ios:設置單元格圖像尺寸
我的代碼遵循本節:
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;
}
});
});
最佳教程,調整大小的圖像與預期的尺寸:http://mobiledevelopertips.com/graphics/how-to-scale-an-image-using-an-objective-c-category.html –
添加一幀到您的圖像查看cell.lotImageView setFrame:CGrectMake(0,0,100,80)]; – AppleDelegate