A UIBarButtonItem that can be badged!
BadgedBarButtonItem can be created programmatically or from a storyboard.
For programmatic use, a badged bar item can be instantiated with
let image = UIImage(imageLiteralResourceName: "barbuttonimage") let buttonFrame: CGRect = CGRect(x: 0.0, y: 0.0, width: image.size.width, height: image.size.height) let barButton = BadgedBarButtonItem( startingBadgeValue: 0, frame: buttonFrame, image: image ) leftBarButton = barButton leftBarButton?.addTarget(self, action: #selector(leftBarButtonTapped(_:))) navigationItem.leftBarButtonItem = leftBarButton
From a storyboard, instantiation is as easy as creating an
IBOutlet and connecting it in Interface Builder:
fileprivate var rightBarButton: BadgedBarButtonItem!
BadgeProperties class to customize the badge bar item's appearance and position.