UITabbarItem-CustomBadge 2.0.3

UITabbarItem-CustomBadge 2.0.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jan 2017

Maintained by Ratul Sharker.




  • By
  • Ratul sharker

Demo

Background

There is no public api from Apple. But it's not impossible to cusotmize the UITabbarItem badge with UILabel. I've been inspired by enryold's repository. I think this could be done in a better way, by overriding the -(void)setBadgeValue:(NSString*)value & the -(NSString*)badgeValue. In this way an existing project doesn't need to change the badge value settings related function calls. This is how the whole thing is maintained.

This project is under the MIT Liecense, feel free to use this code base under compilance.

Installation

Using Cocoapod

pod 'UITabbarItem-CustomBadge'

Manual

Installation of UITabbarItem+CustomBadge is easy, just add UITabbarItem+CustomBadge category in your xcode project. Change the content of this category to meet your requiremnt and you're good to go.

Installation of UITabbarItem+CustomBadge is easy, include following files in your project

Initializing

Now initilaize custom badge in your project's AppDelegate's didFinishLaunchingwithOptions... as follows

//other imports...
#import "UITabbarItem+CustomBadge.h"
#import "DefaultTabbarBadgeAnimation.h"
#import "DefaultSystemLikeBadgeConfiguration.h"


...
...
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

      //supplying the animation parameter
      [UITabBarItem setDefaultAnimationProvider:[[DefaultTabbarBadgeAnimation alloc] init]];
      [UITabBarItem setDefaultConfigurationProvider:[[DefaultSystemLikeBadgeConfiguration alloc] init]];

      //rest of your code goes following...

      return YES;
}

Advance Customization

Customizing the badge appearance

To change a new appearance for the badge, create a new class extending NSObject conforming the protocol UITabbarItemBadgeConfiguration.h. Declare all the properties which are in the protocol. In the implementation file set your appropriate values to meet your requirement. Then to use this configuration implementation set as follows :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

      //
      // here assumed that the MyOwnConfiguration is the class that you made for configuration
      //
      //supplying the animation parameter
      [UITabBarItem setDefaultAnimationProvider:[[DefaultTabbarBadgeAnimation alloc] init]];
      [UITabBarItem setDefaultConfigurationProvider:[[MyOwnConfiguration alloc] init]];

      //rest of your code goes following...

      return YES;
}

Customizing the animation style

In order to provide your own animation, declare a new class extends from NSObject which conforms to the protocol UITabbarItemAnimation.h. Implement two methods of the protocol. Then to use this configuration implementation set as follows :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

      //
      // here assumed that the MyOwnAnimationProvider is the class that you made for configuration
      //
      //supplying the animation parameter
      [UITabBarItem setDefaultAnimationProvider:[[MyOwnAnimationProvider alloc] init]];
      [UITabBarItem setDefaultConfigurationProvider:[[DefaultSystemLikeBadgeConfiguration alloc] init]];

      //rest of your code goes following...

      return YES;
}

Feel free to file an issue if there any.

Change log 2.0.2

  1. Two new animation class are added as the default animation class.
  2. Example project updated to show demonstration of custom animation classes.
  3. Two new animation uses UIViewAnimationOptionAllowUserInteraction which is available ios8.0+ so the project min sdk version changes to ios8.0, if you want to support lower version of SDK please ignore these two animation classes.
  4. Project builded with xcode8.2.1 .