How can I add a badge to a standard UIButton? [closed]

Here's a VERY NICE class by Sascha Paulus called CustomBadge, that builds and renders custom badges using Core Graphics. They're just UIView subclasses, so you lay them out using their frame just like any other UIView subclass.

I've used this library many times and always been pleased with the results. Flexible, easy to use. Totally recommend it.


You can check for several options here: CocoaControls Badges


The class that Apple uses is _UIBadgeView (https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/_UIBadgeView.h), but of course, this class is private (note the underscore) and not documented.

Here's another class that implements this view with the same look and feel as Apple's while also allowing you to customize it: https://github.com/JaviSoto/JSBadgeView. The great thing about this one is that it lets you position the badge relative to another view automatically, in one of its corners.


We have a badge view in Nimbus that's super easy to use and well documented:

NimbusBadge


I don't know how this is done out of the box and I honestly doubt that Apple built that into the SDK.

Anyway, you could create a custom view with a button on it, add the background of the badge as a UIImageView and place a label on it to hold the badge count.

That's a quick solution, it might be better to create a custom subclass of UIButton and add your badge stuff as a subview