码迷,mamicode.com
首页 > 其他好文 > 详细

contentMode

时间:2017-01-11 15:38:26      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:box   uiview   parent   sdi   size   比例   syntax   sub   out   

    • UIView有个UIViewContentMode类型的属性contentMode,可以通过它来修改视图的内容显示模式。

       

      01.typedef NS_ENUM(NSInteger, UIViewContentMode) {
      02.UIViewContentModeScaleToFill,
      03.UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
      04.UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.
      05.UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)
      06.UIViewContentModeCenter,              // contents remain same size. positioned adjusted.
      07.UIViewContentModeTop,
      08.UIViewContentModeBottom,
      09.UIViewContentModeLeft,
      10.UIViewContentModeRight,
      11.UIViewContentModeTopLeft,
      12.UIViewContentModeTopRight,
      13.UIViewContentModeBottomLeft,
      14.UIViewContentModeBottomRight,
      15.};

       

      实例代码:

       

      1.CGRect rect = self.view.frame;
      2.UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
      3.imageView.contentMode = UIViewContentModeTop;
      4.imageView.image = [UIImage imageNamed:@"demoImage"];
      5.[self.view addSubview:imageView];

       

      UIViewContentModeScaleToFill

      根据视图的比例去拉伸图片内容。

      技术分享

      UIViewContentModeScaleAspectFit

      保持图片内容的纵横比例,来适应视图的大小。

      技术分享

      UIViewContentModeScaleAspectFill

      用图片内容来填充视图的大小,多余得部分可以被修剪掉来填充整个视图边界。

      技术分享

      UIViewContentModeRedraw

      这个选项是单视图的尺寸位置发生变化的时候通过调用setNeedsDisplay方法来重新显示。

      UIViewContentModeCenter

      保持图片原比例在视图中间显示图片内容

      如果视图大小小于图片的尺寸,则图片会超出视图边界,下面类同

      技术分享

      UIViewContentModeTop

      保持图片原比例在视图中间顶部显示图片内容

      技术分享

      UIViewContentModeBottom

      保持图片原比例在视图中间底部显示图片内容

      技术分享

      UIViewContentModeLeft

      保持图片原比例在视图中间左边显示图片内容

      技术分享

      UIViewContentModeRight

      保持图片原比例在视图中间右边显示图片内容

      技术分享

      UIViewContentModeTopLeft

      保持图片原比例在视图左上角显示图片内容

      技术分享


      UIViewContentModeTopRight

      保持图片原比例在视图右上角显示图片内容

      技术分享

      UIViewContentModeBottomLeft

      保持图片原比例在视图左下角显示图片内容

      技术分享

      UIViewContentModeBottomRight

      保持图片原比例在视图右下角显示图片内容

      技术分享

contentMode

标签:box   uiview   parent   sdi   size   比例   syntax   sub   out   

原文地址:http://www.cnblogs.com/yecong/p/6273845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!