UIKit框架 - 03.UIImageView
2015-07-12 22:07
465 查看
UIKit框架 - 03.UIImageView
1.基本概念
顾名思义,图片视图就是用来存放图片的,并且可以用来演示动画效果2.图片视图的常用属性和方法
// 1.根据图片快速创建UIImageView控件 UIImage *image = [UIImage imageNamed:@"meinv.jpg"]; // UIImageView *iv = [[UIImageView alloc] initWithImage:image]; UIImageView *iv = [[UIImgaeView alloc] init]; // 2.设置相关属性 iv.backgroundColor = [UIColor redColor];//背景颜色 iv.image = image;//设置图片 iv.image = [UIImage imageNamed:@"meinv.jpg"];//根据图片名称设置图片 // 3.图片内容的显示属性 /* 规律: 但凡取值中包含Scale单词的, 都会对图片进行拉伸(缩放) 但凡取值中没有出现Scale单词的, 都不会对图片进行拉伸 UIViewContentModeScaleToFill, > 会按照UIImageView的宽高比来拉伸图片 > 直到让整个图片都填充UIImageView为止 > 因为是按照UIImageView的宽高比来拉伸, 所以图片会变形 规律: 但凡取值中包含Aspect单词的, 都会按照图片的宽高比来拉伸 > 因为是按照图片的宽高比来拉伸, 所以图片不会变形 UIViewContentModeScaleAspectFit, > 会按照图片的宽高比来拉伸 > 要求整张图片都必须在UIImageView的范围内 > 并且宽度和高度其中一个必须和UIImageView一样 > 居中显示 UIViewContentModeScaleAspectFill, > 会按照图片的宽高比来拉伸 > 要求整张图片必须填充UIImageView > 并且图片的宽度或者高度其中一个必须和UIImageView一样 UIViewContentModeCenter,//居中 UIViewContentModeTop,//顶部对齐 UIViewContentModeBottom,//底部对齐 UIViewContentModeLeft,//左对齐 UIViewContentModeRight,// 右对齐 UIViewContentModeTopLeft,// 左上对齐 UIViewContentModeTopRight, // 右上对齐 UIViewContentModeBottomLeft, // 左下对齐 UIViewContentModeBottomRight, // 右下对齐 */ iv.contentMode = UIViewContentModeScaleAspectFill; //4.剪切超出的部分 iv.clipsToBounds = YES;
3.用UIImageView创建动画效果
UIImageView中有专门的属性可以实现动画效果:@property (nullable, nonatomic, copy) NSArray
// 0.创建可变数组用来动态添加每一张图片 NSMutableArray *arrM = [NSMutableArray array]; // 1.创建图片 for (int i = 1; i <= 6; i++) { NSString *imageNmae = [NSString stringWithFormat:@"run_%i", i]; UIImage *image = [UIImage imageNamed:imageNmae]; // 2.将所有的图片放到数组中 [arrM addObject:image]; } // 3.将保存了所有图片的数组赋值给UIImageView self.imageView.animationImages = arrM; self.imageView.animationRepeatCount = 1; // 设置重复次数 self.imageView.animationDuration = 1;//动画执行时间 [self.imageView startAnimating]; // 开始动画 // [self.imageView stopAnimating]; // 停止动画 // [self.imageView isAnimating]; // 判断是否正在执行动画 }
相关文章推荐
- UIKit框架 -02.UILabel
- UIKit框架-01.UIView
- 设计模式(4) - Builder模式
- 在什么时候用request.getAttribute
- android stuido解决MissingTranslation
- 跟着实例学习设计模式(6)-生成器模式builder(创建型)
- UITableView
- 提高Interface Builder高效工作的8个技巧
- iOS 9: UIStackView入门
- Keil V5.1x命令“Build Target”重新编译所有文件
- Android核心分析之GUI框架的原理
- 详解 UIView 的 Tint Color 属性
- 前端开发工具vue.js开发实践总结
- Java_GUI中GridBagLayout布局使用详解
- Java中GUI界面美化帮助类总结
- iOS --- 去掉UITableView中的空白行
- [LeetCode] Implement Stack using Queues
- 关于querySelector()与querySelectorAll()的在ie下的一点与众不同之处。
- 使用Git、Git GUI和TortoiseGit
- OpenGL蓝宝书第五章5.4Tunnuel 纹理映射和过滤:较好的可读性代码