UITableViewCell subclass that adds a badge accessory view to table view cells.

Meet TDBadgedCell version 2

TDBadgedCell grew out of the need for TableViewCell badges and the lack of them in iOS (see the article explaining this on TUAW). TDBadgedCell was written originally using CGPaths but as more people began to use TDBadgeCell the more customisation people wanted and the class now uses CALayers. TDBadgedCell class also works in both ARC and non-ARC projects automatically (thanks go to Cory Metcalfe).

Adding badges to your UITableViewCell's

TDBadgedCell behaves like anyother UITableViewCell subclass and can be called and dequed in cellForRowAtIndexPath: like Apple's standard table view cell class. (See below for an example)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
	static NSString *CellIdentifier = @"Cell";
	TDBadgedCell *cell = (TDBadgedCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if(cell == nil)
		cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
					reuseIdentifier:CellIdentifier] autorelease];
	cell.badgeString = @"100";
	return cell;

There you have it. Table view cells with badges just like apples own apps. Badges should be used to notify a user of a variable number of items waiting for their attention on the next view controller. For example the number of emails in an inbox, the number of unread direct messages for their twitter account, or game invites pending.

Customising, changing the look and feel…


You're able to change the badge's colour for both normal and highlighted states, the colour of the badged text (by default the text is cut out of the badge), the radius of the badges corners, and whether or not to display shadows on highlighted states.

Below are some example snippets showing what properties TDBadgedCell has to offer and how to modify the look and feel of your TDBadgedCell badges.

Changing the badge's colour
You can set both the normal colour of the badge and its highlighted colour. The defaults are very similar to the iPhone and Mac Mail application.

/* Set the badge colour for the normal state */
cell.badgeColor = [UIColor blueColor];

/* Set the badge colour for the highlighted state */
cell.badgeColorHighlighted = [UIColor pinkColor];

Setting the badge's text color
You can set both the normal colour of the badge and its highlighted colour. The defaults are very similar to the iPhone and Mac Mail application.

/* Set the text colour for all states */
cell.badgeTextColor = [UIColor grayColor];

Setting the badge's shadows
TDBadgedCell provides you with the option to enable drop shadows on title labels, detail text labels, and badges when the cell is selected. This is off by default but can add a lil-something to your cells.

/* Set the text colour for all states */
cell.showShadow = YES;

Setting the badge's corner radius
Changing the corner radius (roundedness) of your badges takes nothing more than changing a single property.

/* Set the corner radius for the badge view */
cell.badge.radius = 9;

Licensing and legal stuff

TDBadgedCell is a free to use class for everyone. I wrote it so people could have the badges Apple never provided us with. If you modify the source please share alike and if you think you've improved upon what I have written I recomend sending me a pull request.

Please note: If you are using TDBadgedCell in your project please make sure you leave credit where credit is due. Chances are I won't notice if you haven't left credit but karma will…

Credits and contributors

TDBadgedCell was originally written to be open source by Tim Davies, and has been used in all kinds of of apps and rewritten in for other toolchains such as monotouch.

TDBadgedCell would be far less usefull if it wasn't for the lovely contributors who have made little tweaks to the source or added entirely new properties. You can view a list of contributors over at the Github Repo

Need some help?

Having a problem using TDBadgedCell? Have an unanswered question? Have no fear! You can contact me using any of the methods below. If its a technical Issue I'd suggest using Github issues as other users may be able to help you with your problem.