如何更改UIBarbutton中的徽章背景颜色?

时间:2015-07-28 07:24:59

标签: ios objective-c uibarbuttonitem uibarbuttonitemstyle uibaritem

我在视图中使用uibarbutton来显示通知徽章编号。我使用了以下代码来显示。

barButtonBadge.badgeValue = @"5";

如何更改此徽章编号的背景颜色? 现在它采用默认颜色。

1 个答案:

答案 0 :(得分:0)

通过你的好问题,我从Lalit Kumar链接上面得到了解决方案。

Add following two libraries in your project

     1. UIButton+Badge.h and UIButton+Badge.m
     2. UIBarButtonItem+Badge.h and  UIBarButtonItem+Badge.m


Also import 

      #import "UIButton+Badge.h"
      #import "UIBarButtonItem+Badge.h"  in required view controller.


 in your required ViewController.m

      UIImage *image2 = [UIImage imageNamed:@"someImage"];
      UIBarButtonItem *navRightButton = [[UIBarButtonItem alloc] initWithImage:image2
                                                                  style:UIBarButtonItemStylePlain
                                                                 target:self
                                                                 action:@selector(buttonPress:)];
     self.navigationItem.leftBarButtonItem = navRightButton;
     self.navigationItem.leftBarButtonItem.badgeValue = @"2";
     self.navigationItem.leftBarButtonItem.badgeBGColor = [UIColor orangeColor]; //Whatever you want just change the color