UIBarButtonItem with a customizable badge for iOS applications
-
Add BadgedBarButtonItem class to your project
-
Create a new object with your image:
let btn = BadgedButtonItem(with: UIImage(named: "your_image"))
- Add the button to the navigation bar
self.navigationItem.rightBarButtonItem = btn
- Customise badge appearance
- Set a tint color
btn.badgeTintColor = .blue
- Set a text color
btn.badgeTextColor = .yellow
- Set badge position (left or right)
btn.position = .left
- Add a border to the badge
btn.hasBorder = true
- Set badge border color
btn.borderColor = .red
- Set bagde size
btn.badgeSize = .medium
- Set badge animation
btn.badgeAnimation = true
- Set the badge with a value
btn.setBadge(with: 1)
- Add an action to the button
btn.tapAction = {
// do something
}