UIImageView的contentMode属性


UIViewContentMode 都有哪些值:

typedef NS_ENUM(NSInteger, UIViewContentMode) {
    UIViewContentModeScaleToFill,
    UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
    UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.
    UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)
    UIViewContentModeCenter,              // contents remain same size. positioned adjusted.
    UIViewContentModeTop,
    UIViewContentModeBottom,
    UIViewContentModeLeft,
    UIViewContentModeRight,
    UIViewContentModeTopLeft,
    UIViewContentModeTopRight,
    UIViewContentModeBottomLeft,
    UIViewContentModeBottomRight,
};

默认值是 0,也就是:

UIViewContentModeScaleToFill

一个个来理解下吧:

  • UIViewContentModeScaleToFill:表示完全填充在 frame 里 不按比例来。
  • UIViewContentModeScaleAspectFit:保持比例,都在 frame 内。
  • UIViewContentModeScaleAspectFill:保持比例,填满但 frame 外也有。
  • UIViewContentModeRedraw:每次设置或更改frame的时候自动调用drawRect.

其他的是相似的,好理解:

  • UIViewContentModeCenter:这个 image 的中心与 frame 的中心重合。
  • UIViewContentModeTop:这个 image 的上边缘与 frame 的上边缘重合。
  • UIViewContentModeBottom:这个 image 的下边缘与 frame 的下边缘重合。
  • UIViewContentModeLeft:这个 image 的左边缘与 frame 的左边缘重合。
  • UIViewContentModeRight:这个 image 的右边缘与 frame 的右边缘重合。
  • UIViewContentModeTopLeft:类似。
  • UIViewContentModeTopRight:类似。
  • UIViewContentModeBottomLeft:类似。
  • UIViewContentModeBottomRight:类似。

经常用到的:1.比如长图的显示 按一定的比例只显示中间的一部分 其他的裁剪掉

   self.imageView.contentMode = UIViewContentModeScaleAspectFill;
   self.imageView.clipsToBounds = YES;

优质内容筛选与推荐>>
1、问题:关于安卓项目设置
2、Python下载与安装
3、WinXP访问局域网共享文件夹无法访问
4、问题不大
5、在使用WCF时如何生成证书认证?


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号