当图片大小超出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;

IOS中UIimageView的内容模式

IOS中UIimageView的内容模式


    

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-06-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案