【发布时间】:2016-07-06 02:41:04
【问题描述】:
在我正在构建的这个小型练习应用程序中,背景应该每 0.25 秒保持一次颜色交替,因为它看起来真的很酷。然而,由于我使用的是“arc4random_uniform”函数,它偶尔会连续两次选择相同的案例,导致我不喜欢的相同颜色的持续时间很长。关于如何消除这些 switch 语句中的立即重复以便它连续两次选择相同的情况的任何想法?
switch arc4random_uniform(10) {
case 0:
self.backgroundImage.backgroundColor = UIColor.redColor()
case 1:
self.backgroundImage.backgroundColor = UIColor.orangeColor()
case 2:
self.backgroundImage.backgroundColor = UIColor.yellowColor()
case 3:
self.backgroundImage.backgroundColor = UIColor.greenColor()
case 4:
self.backgroundImage.backgroundColor = UIColor.blueColor()
case 5:
self.backgroundImage.backgroundColor = UIColor.purpleColor()
case 6:
self.backgroundImage.backgroundColor = UIColor.blackColor()
case 7:
self.backgroundImage.backgroundColor = UIColor.whiteColor()
case 8:
self.backgroundImage.backgroundColor = UIColor.brownColor()
case 9:
self.backgroundImage.backgroundColor = UIColor.grayColor()
case 10:
self.backgroundImage.backgroundColor = UIColor.blackColor()
default:
self.backgroundImage.backgroundColor = UIColor.clearColor()
break;
}
【问题讨论】:
标签: ios xcode swift switch-statement xcode7