Skip to content

drewpitchford/ENMBadgedBarButtonItem-Swift

 
 

Repository files navigation

ENMBadgedBarButtonItem - Swift

CocoaPods

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.

Compatibility:

  • BadgedBarButtonItem is built for Xcode 8.3 and Swift 3.1

About

A navigation bar button item that can be badged

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.4%
  • Objective-C 3.3%
  • Ruby 3.3%