Skip to content

Instantly share code, notes, and snippets.

@heitara
Created February 10, 2020 22:23
Show Gist options
  • Save heitara/294d760b20269a4c2c8a8262a7f23437 to your computer and use it in GitHub Desktop.
Save heitara/294d760b20269a4c2c8a8262a7f23437 to your computer and use it in GitHub Desktop.
Use BadgeContainer Protocol
//custom class
//Don't forget to assigne that custom class to your UIButton views in the storyboard file
class BadgeButton: UIButton, BadgeContainer {
var badgeTimer: Timer?
var badgeView: UIView?
var badgeLabel: UILabel?
}
//here is how to use it in simple view controller
class MyViewController: UIViewController {
@IBOutlet weak var button: BadgeButton!
override func viewDidLoad() {
super.viewDidLoad()
button.showBadge(blink: false, text: "swift")
button.badgeView?.backgroundColor = .blue
button.badgeLabel?.textColor = .orange
}
//here is an example how to hide the badge
func buttonHideBadge() {
button.hideBadge()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment