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.
Asked
Active
Viewed 5,595 times
2
-
http://stackoverflow.com/questions/5684636/how-to-add-badges-on-uibarbutton-item – Kirit Modi Sep 24 '15 at 06:43
-
I am added in ui side directly. – bAthi Sep 24 '15 at 06:43
-
You have to customize all for View. – Kirit Modi Sep 24 '15 at 06:45
-
with out customize any other way is there? – bAthi Sep 24 '15 at 06:45
-
Not then programmatically as above answer, its working fine – Kirit Modi Sep 24 '15 at 06:46
-
By using labels it is possible? – bAthi Sep 24 '15 at 06:48
-
see this link may be helps you http://stackoverflow.com/questions/31337803/how-to-add-small-red-dot-in-uitabbaritem/31338049#31338049 – Anbu.Karthik Sep 24 '15 at 06:49
-
yes, take label instead of Button and giver corner Radius of label, So label is also display same of Badge – Kirit Modi Sep 24 '15 at 06:49
1 Answers
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