UITabbarItem-CustomBadge 2.0.3

UITabbarItem-CustomBadge 2.0.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期最后发布2017年1月

Ratul Sharker 维护。




  • 作者:
  • Ratul sharker

演示

背景

Apple 没有公开的 API。但可以通过 UITabbarItemUILabel 自定义截项徽章。我从 enryold仓库 获得了灵感。我认为可以通过覆盖 -(void)setBadgeValue:(NSString*)value-(NSString*)badgeValue 来做得更好。这样现有的项目就不需要更改徽章值设置相关函数调用。这就是整个维护的原理。

此项目采用 MIT 许可证,您可以在遵守许可证的情况下自由使用此代码库。

安装

使用 Cocoapod

pod 'UITabbarItem-CustomBadge'

手动安装

UITabbarItem+CustomBadge 的安装很简单,只需将 UITabbarItem+CustomBadge 分类添加到您的 Xcode 项目中。更改此分类的内容以满足您的需求即可。

UITabbarItem+CustomBadge 的安装很简单,将以下文件包含到项目中

初始化

现在在项目的 AppDelegatedidFinishLaunchingwithOptions... 方法中初始化自定义徽章,如下所示

//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;
}

如有任何问题,请随时提交问题。

变更日志 2.0.2

  1. 增加了两个新的动画类作为默认动画类。
  2. 示例项目已更新,展示了自定义动画类的演示。
  3. 两个新的动画使用了 UIViewAnimationOptionAllowUserInteraction,该选项自 iOS 8.0 版本开始可用,因此项目最低 SDK 版本更改为 iOS 8.0。如果您想要支持较低版本的 SDK,请忽略这两个动画类。
  4. 该项目在 xcode8.2.1 中构建。