Skip to content

Instantly share code, notes, and snippets.

@patridge
Last active August 23, 2018 15:52
Show Gist options
  • Save patridge/10499338 to your computer and use it in GitHub Desktop.
Save patridge/10499338 to your computer and use it in GitHub Desktop.
Xamarin: get a random color
// 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;
}
@elmarkos23
Copy link

Very Good!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment