Skip to content

Commit

Permalink
Merge pull request #1 from mps/badge_colors
Browse files Browse the repository at this point in the history
Set badge color via Constructor
  • Loading branch information
migueldeicaza committed Dec 3, 2012
2 parents ad9d2c1 + 2ca7be9 commit 8d0ea37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
41 changes: 41 additions & 0 deletions ElementPack/RowBadgeElement.cs
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
}
}

4 changes: 3 additions & 1 deletion Sample/AppDelegate.cs
Expand Up @@ -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)
Expand All @@ -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") {
Expand Down

0 comments on commit 8d0ea37

Please sign in to comment.