简体   繁体   中英

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) 屏幕

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM