iOS UIImageView属性

//创建UIImageView对象:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.frame];
imageView.backgroundColor = [UIColor orangeColor];
//为imageView设置图片:
//    imageView.image = [UIImage imageNamed:@"2.jpg"];

//植物大战僵尸动画:(素材要自己找)
//(1)设置整体背景:
imageView.image = [UIImage imageNamed:@"BackGround"];//png的图知道名字即可,最好使用png格式的图片

//(2)循环创建动画素材(UIImage对象)
NSMutableArray *flowerArray = [NSMutableArray array];
for (NSInteger i = 1; i <= 18; i++) {
    //拼接每个图片的名字:
    NSString *name = [NSString stringWithFormat:@"flower%ld.tiff", i];
    UIImage *image = [UIImage imageNamed:name];
    [flowerArray addObject:image];
}
//(3)创建单独的UIImageView控件
UIImageView *flowerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 80, 73, 74)];

[imageView addSubview:flowerImageView];
//(4)将数组赋值给imageView:
flowerImageView.animationImages = flowerArray;
//(5)设置时间间隔(每两张图片之间播放的时间差)
flowerImageView.animationDuration = 1.8f;
//(6)设置一下重复次数:
//    flowerImageView.animationRepeatCount = 5;
//(7)开始动画:
[flowerImageView startAnimating];

//花儿动起来:
[UIView animateWithDuration:8 animations:^{
    flowerImageView.frame = CGRectMake(200, 400, 73, 74);
}];
//添加到view上
[view addSubview:imageView];

 

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!
技术狗 » iOS UIImageView属性