iOS中 图片的等比例显示

解决方法:高度固定,等比例显示宽度

示例代码如下:

UIImage *picture = [UIImage imageNamed:model.picture];
    _pictureView.image = picture;
    
    // 等比例计算尺寸
    CGFloat pHeight = 150;
    CGFloat pWidth = picture.size.width * pHeight / picture.size.height;
    
    //添加约束
    [_pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(lContent.mas_bottom).offset(margin);
        make.left.equalTo(lContent);
        make.size.mas_equalTo(CGSizeMake(pWidth, pHeight));
    }];

你可能感兴趣的:(iOS中 图片的等比例显示)