Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is it possible to add a standard-looking badge to a standard UIButton?

If it's not supported semi-natively, what would be the simplest way to achieve this?

Example image:

An iPhone UI button

like image 985
ohadpr Avatar asked Jan 18 '11 09:01

ohadpr


3 Answers

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.

like image 149
Dan Ray Avatar answered Nov 10 '22 13:11

Dan Ray


You can check for several options here: CocoaControls Badges

like image 44
Carlos Ricardo Avatar answered Nov 10 '22 13:11

Carlos Ricardo


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.

like image 3
Javier Soto Avatar answered Nov 10 '22 13:11

Javier Soto