使用If循环填充100个图像

时间:2012-11-29 10:08:51

标签: ios6 xcode4.5

我目前正在使用以下代码填充100张图片,但我确信使用If语句有更经济的方法:

mapblock01.image = [UIImage imageNamed:@"block.png"]; mapblock01.hidden = TRUE;
mapblock02.image = [UIImage imageNamed:@"block.png"]; mapblock02.hidden = TRUE;
mapblock03.image = [UIImage imageNamed:@"block.png"]; mapblock03.hidden = TRUE;
mapblock04.image = [UIImage imageNamed:@"block.png"]; mapblock04.hidden = TRUE;
mapblock05.image = [UIImage imageNamed:@"block.png"]; mapblock05.hidden = TRUE;

------>

mapblock99.image = [UIImage imageNamed:@"block.png"]; mapblock99.hidden = TRUE;
mapblock100.image = [UIImage imageNamed:@"block.png"]; mapblock100.hidden = TRUE;

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

对于它,你可以为每个UIImageView提供标签1,2,3..100并设置如下图像:

  for (int i = 0 ; i < 100 ; i++) {
      UIImageView *imageV = (UIImageView *)[self.view viewWithTag:i];
      imageV.image = [UIImage imageNamed:@"block.png"];
      imageV.hidden = TRUE;
}

}