您的位置:首页 > 产品设计 > UI/UE

UIImageView 的contentMode属性

2016-03-16 15:25 621 查看
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,

};

UIImageView * images = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];

images.frame = CGRectMake(100, 150, 50, 10);

images.layer.borderColor = [[UIColor greenColor]CGColor];

images.layer.borderWidth = 1;

UIImageView * images1 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];

images1.frame = CGRectMake(100, 170, 50, 10);

images1.layer.borderColor = [[UIColor greenColor]CGColor];

images1.layer.borderWidth = 1;

images1.contentMode = UIViewContentModeScaleAspectFill;

//UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。

UIImageView * images2 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];

images2.frame = CGRectMake(100, 190, 50, 10);

images2.layer.borderColor = [[UIColor greenColor]CGColor];

images2.layer.borderWidth = 1;

images2.contentMode = UIViewContentModeScaleAspectFit;//采用这种

//UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。

UIImageView * images3 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];

images3.frame = CGRectMake(100, 210, 50, 10);

images3.layer.borderColor = [[UIColor greenColor]CGColor];

images3.layer.borderWidth = 1;

images3.contentMode = UIViewContentModeScaleToFill;

//UIViewContentModeScaleToFill属性会导致图片变形。

[self.view addSubview:images];

[self.view addSubview:images1];

[self.view addSubview:images2];

[self.view addSubview:images3];

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: