1、UIImageView的创建
(1)创建默认默认图片尺寸的UIImageView
//初始化一个UIImageView
UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img01.jpg"]];
//将UIImageView加载到页面
[self.view addSubview:imgV];
(2)创建一个自定义大小和位置的UIImageView
//初始化一个UIImageView
UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img01.jpg"]];
//定义UIImageView的位置和大小
imgV.frame = CGRectMake(100, 100, 100, 100);
//将UIImageView加载到页面
[self.view addSubview:imgV];
**
2、UIImageView帧动画
#import "ViewController.h"
@interface ViewController ()
- (IBAction)start;
- (IBAction)stop;
@property (strong, nonatomic) IBOutlet UIImageView *containerView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
//开始动画
- (IBAction)start{
//创建一个可变数组
NSMutableArray *arrM = [NSMutableArray array];
//创建多张图片
for (int i = 0; i < 81; i++) {
NSString *imageNames = [NSString stringWithFormat:@"drink_%02d.jpg",i];
//实例化图片
UIImage *image = [UIImage imageNamed:imageNames];
//将所有图片放入可变数组中
[arrM addObject:image];}
//将保存了所有图片的数组赋值给UIImageView
self.containerView.animationImages = arrM;
//设置重复次数,0代表无限播放
self.containerView.animationRepeatCount = 1;
//设置一次动画所需时间
self.containerView.animationDuration = 3;
//开始动画
[self.containerView startAnimating];
}
//停止动画
- (IBAction)stop{
if ([self.containerView isAnimating]){
[self.containerView stopAnimating];
}
}
@end
```![请添加图片描述](https://img-blog.csdnimg.cn/f373f5ff4d5b4f42826160f091d4f342.png)