如何为UINavigationItem(UIBarButtonItem)添加徽章 - Swift 3

3
iOS是否提供UIBarButtonItem的徽章?如果没有,如何以编程方式实现或使用任何库(哪些库是最好的)? 屏幕 在图像中,我想在UIBarButtonItem(刷新按钮图标)上显示徽章,例如红色圆形或数字等任何内容。

1
@rkkanojai,我认为iOS不提供UIBarButtonItem的徽章数字。您需要添加一个标签来显示徽章计数。 - Developer
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接