Happily, I found (via The Unofficial Apple Weblog) that Tim Davies had the same idea and already done the hard work, albeit in Objective-C. Tim's code for TDBadgedCell is on github (you can help him out and donate, too), as is the MonoTouch/C# port: TDBadgedCellSharp. Both produce the same output (shown below)
The important stuff (
TDBadgeView and TDBadgeCell) is in TDBadgedCell.cs - the rest of the project is purely for demonstration purposes.Here's a very simple example of how to use the badged cell (warning: doesn't show
DequeueReusableCell which you would normally use in the GetCell method)...public override UITableViewCell GetCell
(UITableView tableView, NSIndexPath indexPath)
{
TDBadgedCell cell = new TDBadgedCell (UITableViewCellStyle.Subtitle, "Cell");
cell.TextLabel.Text = contents[indexPath.Row].Title;
cell.TextLabel.Font = UIFont.BoldSystemFontOfSize (14);
cell.DetailTextLabel.Text = contents[indexPath.Row].Detail;
cell.DetailTextLabel.Font = UIFont.SystemFontOfSize (13);
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
cell.BadgeNumber = Convert.ToInt32 (contents[indexPath.Row].Badge);
if (indexPath.Row == 1)
cell.BadgeColor = UIColor.FromRGBA (1.000f, 0.397f, 0.419f, 1.000f);
if (indexPath.Row == 2)
cell.BadgeColor = UIColor.FromWhiteAlpha (0.783f, 1.000f);
return cell;
}Thanks Tim!
..and finally, if you didn't notice the cover at the top of this page or seen the tweets, "my" book (and Wally, Chris, Martin & Rory's :) is now available from Amazon (and other locations, in paper or PDF)!

This is exactly what I was looking for.
ReplyDeleteThanks Craig.
PS: You have broken link for you github project.
Thanks - links have been updated ;)
ReplyDelete