我们经常使用SDWebimage记载图片,主要记录在tableview中自动计算宽搞并加载图片

 

在cellforRow记载图片

 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

  {

        ImageCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"cell1"];

        if (!cell1) {

            cell1 = [[ImageCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell1"];

        }

        [cell1.imgView sd_setImageWithURL:[NSURL URLWithString:imageURL]];

        cell1.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell1;

}

在这里get Height

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

        UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:name];

        CGFloat height = image.size.height/image.size.width *(WIDTH - 40);//image宽度为屏幕宽度 -40 ,计算宽高比求得对应的高度

        return height;

}