SDWebImageView加载多张图片自适应高度

tableView:

_tableView.estimatedRowHeight = 200;
[cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, MAXFLOAT)];
cell.picString = self.imageArray[indexPath.row];
return UITableViewAutomaticDimension;
-(void)setPicString:(NSString *)picString
{
    _picString = picString;
    __weak typeof(self) strongSelf = self;
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:self.picString] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        [strongSelf changeMaonryByImage:self.picImageView.image];
    }];
}

-(void)changeMaonryByImage:(UIImage *)image
{
    if (image == nil) return;
    //自适应大小
//    float showWidth = YGScreenWidth;
    float showHeight = image.size.height/image.size.width * YGScreenWidth;
    [self.picImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.height.mas_equalTo(showHeight);
        [self layoutIfNeeded];
    }];
}

你可能感兴趣的:(SDWebImageView加载多张图片自适应高度)