這是我已經試過到目前爲止動態改變細胞和UIImage的基於實際圖像的比率高度
我定義一個全局變量
float imgHeight;
然後在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我這樣做
size_t pixelsWide = CGImageGetWidth(scribbleImage.image.CGImage);
size_t pixelsHigh = CGImageGetHeight(scribbleImage.image.CGImage);
CGFloat ratio = 312/pixelsWide;
pixelsHigh = pixelsHigh*ratio;
然後在- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
return pixlesHeight;
現在因爲heightForRowAtIndexPath
被稱爲cellForRowAtIndexPath
之前,我總是得到pixelsHeight as 0
。
我想不出另一種方式做到這一點。我是否應該在heightForRow中重新定義UIImage並執行此操作?
[scribbleImage setImageWithURL: [NSURL URLWithString:scribble[@"scribble_image"]] placeholderImage:[UIImage imageNamed:@"Default.png"]];
那裏還有嗎?應該有一個更簡單的方法來做到這一點。
您的桌子一次只有一張圖片嗎?它在每一行嗎? – rdelmar 2013-03-12 23:51:09
這是非常行。每一行在單元格中只有一個圖像 – Jonathan 2013-03-12 23:56:39
相同的圖像或不同的圖像? – rdelmar 2013-03-12 23:58:24