2017-06-14 40 views
3

在UIBarButtonItem上提供徽章的劑量ios? 如果沒有那麼如何以編程方式做到這一點,或使用任何庫(什麼是最好的圖書館) Screen如何將徽章添加到UINavigationItem(UIBarButtonItem) - Swift 3

在圖像我想告訴喜歡紅色的圓形或數字的任何事情上的UIBarButtonItem徽章(刷新按鈕圖標)。

+1

@rkkanojai我不認爲ios在UIBarButtonItem上提供了徽章號碼。您需要添加一個標籤來顯示徽章數量。 – Developer

回答

3

我使用MIBadgeButton其工作就像一個魅力。

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 
相關問題