TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2017 |
Maintained by Ratul Sharker.
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.
pod 'UITabbarItem-CustomBadge'
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
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;
}
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;
}
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.
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.