Created
February 10, 2020 22:23
-
-
Save heitara/294d760b20269a4c2c8a8262a7f23437 to your computer and use it in GitHub Desktop.
Use BadgeContainer Protocol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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