Last active
August 23, 2018 15:52
-
-
Save patridge/10499338 to your computer and use it in GitHub Desktop.
Xamarin: get a random color
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
// Xamarin.iOS (using MonoTouch.UIKit;) | |
static Random rand = new Random(); | |
public static UIColor GetRandomColor() { | |
int hue = rand.Next(255); | |
UIColor color = UIColor.FromHSB( | |
(hue / 255.0f), | |
1.0f, | |
1.0f); | |
return color; | |
} | |
// Xamarin.Android (using Android.Graphics;) | |
static Random rand = new Random(); | |
public static Color GetRandomColor() { | |
int hue = rand.Next(255); | |
Color color = Color.HSVToColor( | |
new[] { | |
hue, | |
1.0f, | |
1.0f, | |
} | |
); | |
return color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very Good!!