![](/img/trans.png)
[英]How to get the image size of an image file in monotouch without loading it?
[英]Get size of image loading through URL
在我的應用程序中,我在表格視圖中顯示提要。 圖片通過URL發送。 我想根據圖像大小動態計算像元高度。 但是我在單元加載后得到圖像。
如何基於圖像大小實現單元的動態高度?
我希望我的問題很清楚,我會在這里解決。
謝謝,
加載圖像時,可以計算行的所有高度,並且如果分別實現了heightForRowAtIndexPath方法,只需調用[tableView reloadTable]。
如果服務由您自己處理,最簡單的方法是在api中獲取圖像大小。 由於沒有下載圖像,您將無法獲得其大小。
另一種方法是像大多數應用程序一樣,將表行中的imageview
保持恆定大小,並且寬高比填充其中的圖像。
試試這個代碼:
但是您可以使用圖像下載dispatch_async。
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://static.hugedomains.com/images/logo_huge_domains.gif"]];
UIImage *image = [UIImage imageWithData:imageData];
NSLog(@"image height: %f",image.size.height);
NSLog(@"image width: %f",image.size.width);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.