With every new version of your mobile app you have something new to share with the user. The best solution is to hint it with a visual clue. But how to make that gently without annoying the user and keep him curious?
The best and most common approach is to add a notification badge. Yes, this is the tiny red dot at the top which we all know.
This might not fit to your color scheme, then let’s discuss how to make that with code so you can customize it later. The follow snippet shows an elegant solution. The developer can override the default behavior. Protocol oriented principle is used here. This keeps the code clean and reusable.
To use it with a button you have to extend the UIButton class as follows:
After that you can associate any button in your storyboard or use it in your code. No need to do much if you want to use it with other UIView components. Just add the class/structure to suffice the requirements by the BadgeContainer protocol as in the example above.
Ok, so how do we use it? We just call the method showBadge(blink: , text:). The blink will attract extra attention to the badge, if you want a cool pulse animation. Text is what you will see in the badge. You can customize the badgeView and badgeLabel however you like as in the example below:
And don’t forget to hide the badge when you no longer need it with: