我正在使用以下代码为一系列视图设置数组。bunnyView1 到 bunnyView7 是在情节提要中创建的 UIImageView 的实例,但我想自动化该过程,以便我可以使用代码生成连接。我将如何设置循环内的值?
- (void)viewDidLoad
{
NSMutableArray *hopAnimation = [[NSMutableArray alloc] initWithCapacity:20];
for (int i = 1; i <= 20; i++) {
[hopAnimation addObject:[UIImage imageNamed:[NSString stringWithFormat:@"frame-%i.png", i]]];
}
self.bunnyView1.animationImages=hopAnimation;
self.bunnyView2.animationImages=hopAnimation;
self.bunnyView3.animationImages=hopAnimation;
self.bunnyView4.animationImages=hopAnimation;
self.bunnyView5.animationImages=hopAnimation;
self.bunnyView6.animationImages=hopAnimation;
self.bunnyView7.animationImages=hopAnimation;
self.bunnyView1.animationDuration=1;
self.bunnyView2.animationDuration=1;
self.bunnyView3.animationDuration=1;
self.bunnyView4.animationDuration=1;
self.bunnyView5.animationDuration=1;
self.bunnyView6.animationDuration=1;
self.bunnyView7.animationDuration=1;
[super viewDidLoad];
}