iOS制作gif动态图

时间:2024-06-22 13:35:20

NSMutableArray * array = [NSMutableArray array];

for (int i = 1; i < 6; i++) {

NSString * string = [NSString stringWithFormat:@"hehua0%d",i];

UIImage * image = [UIImage imageNamed:string];

[array addObject:image];

}

self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];

//设置动画图片

self.imageView.animationImages = array;

//动画时间

self.imageView.animationDuration = 1;

//动画播放重复次数,值为0时,无限循环

self.imageView.animationRepeatCount = 0;

//开始动画

[self.imageView startAnimating];

[self.view addSubview:self.imageView];