R kanojia
R kanojia

Reputation: 105

How to add badge to UINavigationItem (UIBarButtonItem) - Swift 3

Dose ios providing badge on UIBarButtonItem? if not then how to do it programmatically or use any library(what are the best library) Screen

In image i want to show badge on UIBarButtonItem (Refresh button icon) like red color round or numbers any thing.

Upvotes: 3

Views: 1627

Answers (1)

Dharma
Dharma

Reputation: 3013

I'm using MIBadgeButton its working like a charm.

var appNotificationBarButton: MIBadgeButton!      // Make it global
self.appNotificationBarButton = MIBadgeButton(frame: CGRect(x: 0, y: 0, width: 50, height: 40))
self.appNotificationBarButton.setImage(UIImage(named: "bell"), for: .normal)
self.appNotificationBarButton.badgeEdgeInsets = UIEdgeInsetsMake(10, 0, 0, 10)
self.appNotificationBarButton.addTarget(self, action: #selector(self.appNotificationClicked), for: .touchUpInside)
let App_NotificationBarButton : UIBarButtonItem = UIBarButtonItem(customView: self.appNotificationBarButton)
self.navigationItems.rightBarButtonItem = App_NotificationBarButton

Upvotes: 3

Related Questions