diff --git a/ElementPack/RowBadgeElement.cs b/ElementPack/RowBadgeElement.cs index 02b4d6b..360138f 100644 --- a/ElementPack/RowBadgeElement.cs +++ b/ElementPack/RowBadgeElement.cs @@ -60,12 +60,43 @@ public RowBadgeElement (string caption, NSAction tapped) : this(caption) { Tapped += tapped; } + + public RowBadgeElement (string caption, string badgeValue, string hexColor) : this(caption, badgeValue) + { + int red = 0, green = 0, blue = 0; + + if (hexColor.Length == 6) { + red = int.Parse (hexColor.Substring (0, 2), System.Globalization.NumberStyles.AllowHexSpecifier); + green = int.Parse (hexColor.Substring (2, 2), System.Globalization.NumberStyles.AllowHexSpecifier); + blue = int.Parse (hexColor.Substring (4, 2), System.Globalization.NumberStyles.AllowHexSpecifier); + } else if (hexColor.Length == 3) { + red = int.Parse ( + hexColor.Substring (0, 1) + hexColor.Substring (0, 1), + System.Globalization.NumberStyles.AllowHexSpecifier + ); + green = int.Parse ( + hexColor.Substring (1, 1) + hexColor.Substring (1, 1), + System.Globalization.NumberStyles.AllowHexSpecifier + ); + blue = int.Parse ( + hexColor.Substring (2, 1) + hexColor.Substring (2, 1), + System.Globalization.NumberStyles.AllowHexSpecifier + ); + } + + this.Color = UIColor.FromRGB (red, green, blue); + } public RowBadgeElement (string caption, string badgeValue, NSAction tapped) : this(caption, badgeValue) { Tapped += tapped; } + public RowBadgeElement (string caption, string badgeValue, NSAction tapped, string hexColor) : this(caption, badgeValue, hexColor) + { + Tapped += tapped; + } + public event NSAction Tapped; public override UITableViewCell GetCell (UITableView tv) @@ -248,5 +279,15 @@ public override void SetHighlighted (bool highlighted, bool animated) } } } + + public static class BadgeColors + { + public const string DEFAULT = "999"; + public const string SUCCESS = "468847"; + public const string WARNING = "F89406"; + public const string IMPORTANT = "B94A48"; + public const string INFO = "3A87AD"; + public const string INVERSE = "333"; + } } diff --git a/Sample/AppDelegate.cs b/Sample/AppDelegate.cs index ae39b8a..3068593 100644 --- a/Sample/AppDelegate.cs +++ b/Sample/AppDelegate.cs @@ -29,6 +29,8 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) new RowBadgeElement ("Colored", "color", () => {}) { Color = UIColor.FromRGBA (0.792f, 0.197f, 0.219f, 1f) }, + new RowBadgeElement ("Colored with default coloring", "5", BadgeColors.WARNING) { + }, new RowBadgeElement ("With radius", "9f", () => {}) { Radius = 9f, Color = UIColor.FromRGBA (0.197f, 0.592f, 0.219f, 1f) @@ -41,7 +43,7 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) BackgroundColor = UIColor.Red, Radius = 9f, Color = UIColor.FromRGBA (0.197f, 0.592f, 0.219f, 1f) - }, + } }; var counterSection = new Section("Counter Elements") {