IOS中UIimageView的内容模式

        当图片大小超出imageView时, 会只有部分图片显示在imageView上。当UIImageView的大小和图片大小不相符的时候, 为了达到合适的图片设置效果, 通常设置UIImageView 的contentMode 属性即可(contentMode属性继承于其父类UIViwe)。

图片的对齐方式: 上下右左,中

图片的缩放方式: 左上角缩放、中心点缩放

  

 //不带有Scale,标明图片不可能被拉伸或压缩,图片的对齐方式

     UIViewContentModeCenter,

     UIViewContentModeTop,

     UIViewContentModeBottom,

     UIViewContentModeLeft,

     UIViewContentModeRight,

     UIViewContentModeTopLeft,

     UIViewContentModeTopRight,

     UIViewContentModeBottomLeft,

     UIViewContentModeBottomRight,

以上属性, 当图片大小超出imageView时, 会只有部分图片显示在imageView上。

   // 图片拉伸设置

UIViewContentModeScaleToFill, 使图片缩放来填充满imageView. 

  // 用的最多这个


UIViewContentModeScaleAspectFit

 // 宽高等比例缩放

     // 直到图片完全被ImageView包裹,可能会导致出现imageView空白区域,

     // 应用: Android版本的百思不得姐视频imageview预览

 


UIViewContentModeScaleAspectFill

// 宽高比不变 Fill填充,图片可能超过imageview,

     // 按照等比例缩放,知道图片宽或高被imageview包裹,可能会图片宽或高度超过imageView

  

  如果超过的部分不想要: 可以直接裁剪

 imageView.clipsToBounds = YES;

 

    

 

猜你喜欢

转载自blog.csdn.net/dreams_deng/article/details/78264874