如何将一系列相似的行转换为 for 循环?
我正在为 iPhone 编写一个应用程序。我还不太擅长循环。如何将这段代码缩短为 for 循环?
if(CGRectContainsRect([space1 frame], [box frame])){
space1.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space2 frame], [box frame])){
space2.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space3 frame], [box frame])){
space3.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space4 frame], [box frame])){
space4.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space5 frame], [box frame])){
space5.image = [UIImage imageNamed:@"box.png"];
}
I'm programming an app for the iPhone. I'm not very good with loops just yet. How do I shorten this code into a for loop?
if(CGRectContainsRect([space1 frame], [box frame])){
space1.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space2 frame], [box frame])){
space2.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space3 frame], [box frame])){
space3.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space4 frame], [box frame])){
space4.image = [UIImage imageNamed:@"box.png"];
}
else if(CGRectContainsRect([space5 frame], [box frame])){
space5.image = [UIImage imageNamed:@"box.png"];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)