Skip to content

zaidiabbas/ENMBadgedBarButtonItem-Swift

 
 

Repository files navigation

ENMBadgedBarButtonItem - Swift

Swift CocoaPods Carthage compatible

A UIBarButtonItem that can be badged!

Screenshot


Usage

A 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:

@IBOutlet fileprivate var rightBarButton: BadgedBarButtonItem!

Use the BadgeProperties class to customize the badge bar item's appearance and position.

About

A navigation bar button item that can be badged

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.3%
  • Objective-C 3.4%
  • Ruby 3.3%