Last active
October 6, 2015 11:45
-
-
Save kiwiznesic/fc90c319d8d6b029752f to your computer and use it in GitHub Desktop.
Get random UIColor with Swift
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
| /* | |
| UIColor class method that returns a random color. All parameters are optional. | |
| */ | |
| import UIKit | |
| extension UIColor{ | |
| class func randomColor(hue:CGFloat? = ( CGFloat( CGFloat(arc4random()) % 256 / 256.0 ) ), | |
| saturation:CGFloat? = ( CGFloat( CGFloat(arc4random()) % 128 / 256.0 ) + 0.5 ), | |
| brightness:CGFloat? = ( CGFloat( CGFloat(arc4random()) % 128 / 256.0 ) + 0.5 ), | |
| alpha:CGFloat? = CGFloat(1.0)) -> UIColor{ | |
| return UIColor(hue: hue!, saturation: saturation!, brightness: brightness!, alpha: alpha!); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment