美文网首页
UIImageview的contentmode属性介绍

UIImageview的contentmode属性介绍

作者: 搬砖行家 | 来源:发表于2017-12-18 13:50 被阅读0次

    这一属性通常用于实现可调整大小的控制,通常与contentStretch属性一起使用。通过使用这一属性来决定你扩充的模式,从而避免了之前每次都要重新对view的内容进行重画.

    UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下几个常量可供设定:

    UIViewContentModeScaleToFill

    UIViewContentModeScaleAspectFit

    UIViewContentModeScaleAspectFill

    UIViewContentModeRedraw

    UIViewContentModeCenter

    UIViewContentModeTop

    UIViewContentModeBottom

    UIViewContentModeLeft

    UIViewContentModeRight

    UIViewContentModeTopLeft

    UIViewContentModeTopRight

    UIViewContentModeBottomLeft

    UIViewContentModeBottomRight

    注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。

    例如:

    1。显示正常的图片

    [cpp]view plaincopy

    _image = [[UIImageView alloc] init];

    image = [UIImage imageNamed:@"12.jpeg"];

    _image.backgroundColor = [UIColor brownColor];

    _image.clipsToBounds = YES;

    _image.frame = CGRectMake(100, 130, 100, 100);

    _image.contentMode = UIViewContentModeScaleToFill;

    [self.view addSubview:_image];

    [图片上传失败...(image-c57940-1482040171368)]

    2。

    [cpp]view plaincopy

    _image.contentMode = UIViewContentModeScaleAspectFill;

    [图片上传失败...(image-5710b0-1482040171368)]

    3。

    [cpp]view plaincopy

    _image.contentMode = UIViewContentModeScaleAspectFit;

    [图片上传失败...(image-feb916-1482040171368)]

    相关文章

      网友评论

          本文标题:UIImageview的contentmode属性介绍

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