UIImageView02

UIImageView相当于⼀个相框,⽤来显⽰图⽚,⾥边可以是⼀张图⽚,也可以是⼀组图⽚
 
//
//  ViewController.m
//  UIImageView 02
//
//  Created by cqy on 16/2/15.
//  Copyright © 2016年 程清杨. All rights reserved.
//

#import "ViewController.h"

@interface ViewController (){
    UIImageView *img;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    img = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
    img.backgroundColor = [UIColor whiteColor];
    // 不要将数据写⼊view
    // 准备⼀个image的数组
    NSMutableArray *imArr = [NSMutableArray array];
    // 循环⽣成image放⼊数组
    for(int i = 1; i < 4;i++){
        NSString *nameStr = [NSString stringWithFormat:@"%d",i];
        NSLog(@"-----%d",i);
           [imArr addObject:[UIImage imageNamed:nameStr]];
        }
    //执⾏⼀组所⽤时间
    img.animationDuration = 1;
    //循环三次
    img.animationRepeatCount = 3;
    // 将image数组 赋值给animationImages
    img.animationImages = imArr;
    //开始动画
    [img startAnimating];
    //结束动画
    //[img stopAnimating];
    [self.view addSubview:img];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
原文地址:https://www.cnblogs.com/iQingYang/p/5193204.html