gpt4 book ai didi

objective-c - 如何动态设置属性

转载 作者:行者123 更新时间:2023-11-28 22:57:02 25 4
gpt4 key购买 nike

我正在使用以下代码为一系列 View 设置数组。 bunnyView1 到 bunnyView7 是在 Storyboard中创建的 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];

最佳答案

将您的变量添加到数组中。并迭代数组并设置值。例如,

NSArray *collection = [[NSArray    alloc]initWithObjects:@"object1",@"object2",@"object3",@"object4",nil];

关于objective-c - 如何动态设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10583604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com