0

I am creating an app i want to show badge icon when there an notification to alert for user.

I have found out library named PPBadgeView and i have followed the following instruction which i am using pod 'PPBadgeViewSwift' and then pod install

In programming i want to implement rightNavigationBar with the badgeview but it doesn't show me.

What i have done:

let rightBarButton = UIBarButtonItem(image: UIImage(named: "notification")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), style: .plain, target: self, action: #selector(notificationHandle))

rightBarButton.pp.addBadge(text: "99+")
rightBarButton.pp.moveBadge(x: -5, y: 0)
rightBarButton.pp.setBadge(height: 12)
rightBarButton.pp.setBadge(flexMode: PPBadgeViewFlexMode.tail)

self.navigationItem.rightBarButtonItem = rightBarButton

When i run the app i just see the icon that i have set only. I don't know where is my badgeView.

Visal Sambo
  • 1,270
  • 1
  • 19
  • 33

1 Answers1

1

If you are using iOS 11+ you have to async the task

let rightBarButton = UIBarButtonItem(image: UIImage(named: "notification")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), style: .plain, target: self, action: #selector(notificationHandle))
self.navigationItem.rightBarButtonItem = rightBarButton

if (UIDevice.current.systemVersion as NSString).doubleValue >= 11.0 {
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.01, execute: {
        rightBarButton.pp.addBadge(text: "99+")
        rightBarButton.pp.moveBadge(x: -5, y: 0)
        rightBarButton.pp.setBadge(height: 12)
        rightBarButton.pp.setBadge(flexMode: PPBadgeViewFlexMode.tail)
    })
} else {
    rightBarButton.pp.addBadge(text: "99+")
    rightBarButton.pp.moveBadge(x: -5, y: 0)
    rightBarButton.pp.setBadge(height: 12)
    rightBarButton.pp.setBadge(flexMode: PPBadgeViewFlexMode.tail)
}