waylonion
waylonion

Reputation: 6976

TableView Row with a badge number

How can I add a badge icon to a row in a table view? An example of this would be the mail app in iOS where the inbox row has a badge icon showing you the number of unread messages? Thanks!

Upvotes: 2

Views: 1763

Answers (3)

FluffulousChimp
FluffulousChimp

Reputation: 9185

TDBadgedCell is a good solution for this requirement.

Upvotes: 3

Legolas
Legolas

Reputation: 12335

Either create a custom tableViewCell with a UILabel as a subview in it, or add the UILabel to a cell's contentView.

I would recommend creating your own (custom) tableViewCell though.

To get the badge shape for your label, you can play with 'cornerRadius' to get a round shape, and set the backgroundColor, textColor and borderWidth, and borderColor. Once you get the unreadCount, just assign it to your customCell's badgeLabel's text property.

Simple as that !

Upvotes: 1

Benny
Benny

Reputation: 5092

You will have to create it yourself as there are no template cells for this. Luckily its very simple, create a custom cell with a styled label for the number and update it in cellForRowAtIndexPath: based on the information in your model object.

Upvotes: 1

Related Questions