美文网首页iOS学习笔记iOS Developer
iOS中 图片的等比例显示

iOS中 图片的等比例显示

作者: 吖几角 | 来源:发表于2016-08-16 02:12 被阅读334次

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

    示例代码如下:

    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中 图片的等比例显示

        本文链接:https://www.haomeiwen.com/subject/aagqsttx.html