我想制作一个图像生成器,但我唯一能在任何地方找到的是一个随机的,但我需要它们是一个特定的顺序。
这是我所拥有的,但我不希望图像按随机顺序排列:
.h 文件
@interface ViewController :UIViewController {
IBOutlet UIImageView *imageview;
IBOutlet UIImageView *imageview2;
}
-(IBAction)randomimagebutton;
-(IBAction)randomimagebutton2;
@end
.m 文件
-(IBAction)randomimagebutton {
int randomimages = rand() % 8;
switch (randomimages) {
case 0:
imageview.image = [UIImage imageNamed:@"eye right wihte.png"];
break;
case 1:
imageview.image = [UIImage imageNamed:@"eye right red.png"];
break;
case 2:
imageview.image = [UIImage imageNamed:@"eye right pink.png"];
break;
case 3:
imageview.image = [UIImage imageNamed:@"eye right light blue.png"];
break;
case 4:
imageview.image = [UIImage imageNamed:@"eye right dark blue.png"];
break;
case 5:
imageview.image = [UIImage imageNamed:@"eye right light green.png"];
break;
case 6:
imageview.image = [UIImage imageNamed:@"eye right dark green.png"];
break;
case 7:
imageview.image = [UIImage imageNamed:@"eye right orange.png"];
break;
case 8:
imageview.image = [UIImage imageNamed:@"eye right yellow.png"];
break;
default:
break;
}
}
-(IBAction)randomimagebutton2 {
int randomimages = rand() % 8;
switch (randomimages) {
case 0:
imageview2.image = [UIImage imageNamed:@"eye left white.png"];
break;
case 1:
imageview2.image = [UIImage imageNamed:@"eye left red.png"];
break;
case 2:
imageview2.image = [UIImage imageNamed:@"eye left pink.png"];
break;
case 3:
imageview2.image = [UIImage imageNamed:@"eye left light blue.png"];
break;
case 4:
imageview2.image = [UIImage imageNamed:@"eye left dark blue.png"];
break;
case 5:
imageview2.image = [UIImage imageNamed:@"eye left light green.png"];
break;
case 6:
imageview2.image = [UIImage imageNamed:@"eye left dark green.png"];
break;
case 7:
imageview2.image = [UIImage imageNamed:@"eye left orange.png"];
break;
case 8:
imageview2.image = [UIImage imageNamed:@"eye left yellow.png"];
break;
default:
break;
}
}