在UIImageView的使用中,有时需要用代码设置其内图片内容的填充模式,
为方便以后工作方便查找使用,现把各种模式测试如下
// 测试图片内容填充模式
static int a;
-(void)test1{
self.imageV.image = [UIImage imageNamed:@"aa.jpg"];
// 改变内部内容的填充方式
self.imageV.contentMode = a;
// 显示模式文字
UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 300, 375, 100)];
NSArray *arr = @[
@"UIViewContentModeScaleToFill", // 拉伸自适应填满整个视图
@"UIViewContentModeScaleAspectFit", // 自适应比例大小显示
@"UIViewContentModeScaleAspectFill", // 原始大小显示
@"UIViewContentModeRedraw", // 尺寸改变时重绘
@"UIViewContentModeCenter", // 中间
@"UIViewContentModeTop", // 顶部
@"UIViewContentModeBottom", // 底部
@"UIViewContentModeLeft", // 中间贴左
@"UIViewContentModeRight", // 中间贴右
@"UIViewContentModeTopLeft", // 贴左上
@"UIViewContentModeTopRight", // 贴右上
@"UIViewContentModeBottomLeft", // 贴左下
@"UIViewContentModeBottomRight", // 贴右下
];
lab.text = arr[a++];
lab.font = [UIFont systemFontOfSize:20];
[self.lab removeFromSuperview];
[self.imageV addSubview:lab];
self.lab = lab;
NSLog(@"%s 模式%d",__func__,a);
if (a == 13) a = 0;
}