1. UIImageView基本使用
/*
注意:
如果是通过[[UIImageView alloc] init];创建的图片, 没有默认的宽高
但是如果是通过[[UIImageView alloc] initWithImage:image];创建的图片, 有默认的宽高
默认的宽高就是图片的宽高
修改控件的frame的注意点:
// 注意: OC语法规定, 不能直接修改一个"对象"的"结构体属性"的"成员"
// 如果不能直接修改一个"对象"的"结构体属性"的"成员", 那么如果真的想改怎么办?
// iv.frame.size = image.size; // 错误
/* 正确做法:先取出 --> 再修改 --> 重新赋值 */
iv.frame = CGRectMake(0, 0, image.size.width, image.size.height);
// iv.frame = (CGRect){{0, 0}, {image.size.width, image.size.height}};
// 一个{}对应一个结构体
iv.frame = (CGRect){{0, 0}, {image.size.width, image.size.height}};
iv.image = [UIImage imageNamed:@"meinv.jpg"];
iv.contentMode = UIViewContentModeScaleAspectFill;
// 剪切超出的部分
iv.clipsToBounds = YES;
NSMutableArray *arrM = [NSMutableArray array];
// 1.创建图片
for (int i = 1; i <= 10; i++) {
NSString *imageNmae = [NSString stringWithFormat:@"stand_%i", i];
UIImage *image = [UIImage imageNamed:imageNmae];
// 2.将所有的图片放到数组中
[arrM addObject:image];
}
// 3.将保存了所有图片的数组赋值给UIImageView
self.containerView.animationImages = arrM;
self.containerView.animationRepeatCount = 1; // 设置重复次数
self.containerView.animationDuration = 1;
[self.containerView startAnimating]; // 开始动画
/* iv.contentMode = UIViewContentModeScaleAspectFill;
规律:
但凡取值中包含Scale单词的, 都会对图片进行拉伸(缩放)
但凡取值中没有出现Scale单词的, 都不会对图片进行拉伸
UIViewContentModeScaleToFill,
> 会按照UIImageView的宽高比来拉伸图片
> 直到让整个图片都填充UIImageView为止
> 因为是按照UIImageView的宽高比来拉伸, 所以图片会变形
规律:
但凡取值中包含Aspect单词的, 都会按照图片的宽高比来拉伸
> 因为是按照图片的宽高比来拉伸, 所以图片不会变形
UIViewContentModeScaleAspectFit,
> 会按照图片的宽高比来拉伸
> 要求整张图片都必须在UIImageView的范围内
> 并且宽度和高度其中一个必须和UIImageView一样
> 居中显示
UIViewContentModeScaleAspectFill,
> 会按照图片的宽高比来拉伸
> 要求整张图片必须填充UIImageView
> 并且图片的宽度或者高度其中一个必须和UIImageView一样
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
*/
/*
注意: