我有 4 个UIButtons
我想以随机顺序闪烁较浅的彩色图像一秒钟。所以很明显我想以编程方式更改按钮图像。正如您在XCode Project方法中看到的:showSequence,它尝试将图像设置为较亮的图像,然后再返回,但它不会显示在模拟器上。
代码片段:
- (void) showSequence:(NSMutableArray *)sequenceArray {
for(int i = 0; i < [sequenceArray count]; i++){
int sequenceNumber = [[sequenceArray objectAtIndex:i] intValue];
switch (sequenceNumber) {
case 1: {
NSLog(@"green");
[self.greenButton setBackgroundImage:[UIImage imageNamed:@"green_active.png"] forState:UIControlStateNormal];
sleep(1);
[self.greenButton setBackgroundImage:[UIImage imageNamed:@"green_inactive.png"] forState:UIControlStateNormal];
break;
}
case 2: {
NSLog(@"red");
[self.redButton setBackgroundImage:[UIImage imageNamed:@"red_active.png"] forState:UIControlStateNormal];
sleep(1);
[self.redButton setBackgroundImage:[UIImage imageNamed:@"red_inactive.png"] forState:UIControlStateNormal];
break;
}
case 3: {
NSLog(@"yellow");
[self.yellowButton setBackgroundImage:[UIImage imageNamed:@"yellow_active.png"] forState:UIControlStateNormal];
sleep(1);
[self.yellowButton setBackgroundImage:[UIImage imageNamed:@"yellow_inactive.png"] forState:UIControlStateNormal];
break;
}
case 4: {
NSLog(@"blue");
[self.blueButton setBackgroundImage:[UIImage imageNamed:@"blue_active.png"] forState:UIControlStateNormal];
sleep(1);
[self.blueButton setBackgroundImage:[UIImage imageNamed:@"blue_inactive.png"] forState:UIControlStateNormal];
break;
}
default:
break;
}
}
}
在此先感谢(顺便说一句,在它会中断的序列中不要点击开始按钮(我仍在努力))