如何更改iOS UITabBar徽章值位置?

时间:2016-05-27 01:49:00

标签: ios objective-c user-interface uitabbaritem

three

以下是我的AppDelegate.m 中的代码:

RootTableViewController *fcTableViewController = [[RootTableViewController alloc]
                                                  initWithStyle:UITableViewStylePlain];
fcTableViewController.title = @"root";
UINavigationController *fcNavigationController = [[UINavigationController alloc]
                                                  initWithRootViewController:fcTableViewController];
fcNavigationController.navigationBar.translucent = NO;
fcNavigationController.tabBarItem.badgeValue = @"0";

// ?
fcNavigationController.tabBarItem.image = [[UIImage imageNamed:@"icon1"]
                                           imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
fcNavigationController.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

FaiChouViewController *fcViewController = [[FaiChouViewController alloc] init];
UINavigationController *fcNController = [[UINavigationController alloc] initWithRootViewController:fcViewController];
fcNController.navigationBar.translucent = YES;
fcNController.tabBarItem.badgeValue = @"1";
// ...
UITabBarController *fcTabBarController = [[UITabBarController alloc] init];
fcTabBarController.viewControllers = @[fcNavigationController, fcNController, fcpNavigationController];

self.window.rootViewController = fcTabBarController;

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

这是我的问题:

为什么我手机上的徽章价值1不在正确的位置?

如何解决?

1 个答案:

答案 0 :(得分:0)

昨天前一天我遇到了同样的问题,你可以查看here

演示

enter image description here

只有两行代码可以帮助您入门

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