Last active
May 18, 2017 23:53
-
-
Save DTHENG/77be4c88ebe5962fa5b648d13e90c533 to your computer and use it in GitHub Desktop.
Random color from UIColor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIColor { | |
static func random() -> UIColor { | |
switch (arc4random_uniform(15)) { | |
case 0: | |
return UIColor.blackColor() | |
case 1: | |
return UIColor.darkGrayColor() | |
case 2: | |
return UIColor.lightGrayColor() | |
case 3: | |
return UIColor.whiteColor() | |
case 4: | |
return UIColor.grayColor() | |
case 5: | |
return UIColor.redColor() | |
case 6: | |
return UIColor.greenColor() | |
case 7: | |
return UIColor.blueColor() | |
case 8: | |
return UIColor.cyanColor() | |
case 9: | |
return UIColor.yellowColor() | |
case 10: | |
return UIColor.magentaColor() | |
case 11: | |
return UIColor.orangeColor() | |
case 12: | |
return UIColor.purpleColor() | |
case 13: | |
return UIColor.brownColor() | |
default: | |
return UIColor.clearColor() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment