测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布日期最后发布 | 2017年1月 |
由 Ratul Sharker 维护。
Apple 没有公开的 API。但可以通过 UITabbarItem 和 UILabel 自定义截项徽章。我从 enryold 的 仓库 获得了灵感。我认为可以通过覆盖 -(void)setBadgeValue:(NSString*)value
和 -(NSString*)badgeValue
来做得更好。这样现有的项目就不需要更改徽章值设置相关函数调用。这就是整个维护的原理。
此项目采用 MIT 许可证,您可以在遵守许可证的情况下自由使用此代码库。
pod 'UITabbarItem-CustomBadge'
UITabbarItem+CustomBadge
的安装很简单,只需将 UITabbarItem+CustomBadge 分类添加到您的 Xcode 项目中。更改此分类的内容以满足您的需求即可。
UITabbarItem+CustomBadge
的安装很简单,将以下文件包含到项目中
现在在项目的 AppDelegate
的 didFinishLaunchingwithOptions...
方法中初始化自定义徽章,如下所示
//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;
}
要更改徽章的新外观,创建一个新的继承自 NSObject
并符合协议 UITabbarItemBadgeConfiguration.h 的类。声明协议中的所有属性。在实现文件中设置合适的值以满足您的需求。然后为了使用此配置实现设置,如下所示
- (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;
}
为了提供自己的动画,声明一个新的继承自 NSObject
的类,使其符合 UITabbarItemAnimation.h 协议。实现协议中的两个方法。然后,将此配置实现设置为如下
- (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;
}
如有任何问题,请随时提交问题。
UIViewAnimationOptionAllowUserInteraction
,该选项自 iOS 8.0 版本开始可用,因此项目最低 SDK 版本更改为 iOS 8.0。如果您想要支持较低版本的 SDK,请忽略这两个动画类。