2

I am using uibarbutton in my view to show the notification badge number. I have used following code to display.

barButtonBadge.badgeValue = @"5";

How can I change the background color of this badge number? Right now it is taking default color.

user3182143
  • 9,459
  • 3
  • 32
  • 39
  • A badge is a small red oval that displays the number of pending notification items (a badge appears over the upper-right corner of an app’s icon). You have no control over the size or color of the badge. – Kumar Jul 28 '15 at 07:41
  • https://github.com/mikeMTOL/UIBarButtonItem-Badge – Kumar Jul 28 '15 at 07:43

1 Answers1

0

Through your good question i got the solution from above Lalit Kumar link.

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
user3182143
  • 9,459
  • 3
  • 32
  • 39