目前在cellForRowAtIndexPath中显示uiimageview时,我计算图像的高度并将其存储在CGFloat scaledHeight
中如何调整单元格大小并使其等于此高度?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"PhotoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PFFile *userImageFile = object[@"image"];
[userImageFile getDataInBackgroundWithBlock:^(NSData * _Nullable data, NSError * _Nullable error) {
if (!error) {
// // UIImageView *imageView = (UIImageView *)[cell viewWithTag:1];
UIImage *image = [UIImage imageWithData:data];
// imageView.image = image;
UIImageView *test = [[UIImageView alloc]init];
test.image = image;
CGSize imgSize = image.size;
CGFloat ratio = self.view.window.frame.size.width/imgSize.width;
CGFloat scaledHeight = imgSize.height * ratio;
[test setFrame:CGRectMake(0, 0, self.view.window.frame.size.width, scaledHeight)];
NSLog(@"HEIGHT:%f",scaledHeight);
[cell addSubview:test];
}
} progressBlock:^(int percentDone)
{
NSLog(@"done");
}];
.....
这是我的heightForRowAtindexPath(我的总数设置为500.0f,但有些图像的高度为250,所以还有很多额外的空间。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 500.0f;
}