2

I am new for iOS mobile developing.I want to add badge for UIbarbuttonitem.I am added UIbarbuttonitem in UI side.Can you please help me any one.Thanks in advance.

bAthi
  • 341
  • 4
  • 20

1 Answers1

10

Download class from here UIBarButtonItem-Badge and import in your project only UIBarButtonItem+Badge.h or UIBarButtonItem+Badge.m class in project and import in your class

#import "UIBarButtonItem+Badge.h"

write down only one line for set badge

self.navigationItem.rightBarButtonItem.badgeValue = @"5"; //your value 

Swift 3

for me, it was not working without DispatchQueue

        DispatchQueue.main.async {
            self.navigationItem.rightBarButtonItem.badgeBGColor = UIColor.red
            self.navigationItem.rightBarButtonItem.badgeValue = "\(5)"
        }
Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35