Bedgeable is a protocol can display badge into your any custom UI components or even apply all UIView.
- iOS 8.0+
- Xcode 8.0+
- Swift 3.0+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate Badgeable into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target '<Your Target Name>' do
pod 'Badgeable'
end
Then, run the following command:
$ pod install
Will support Carthage soon.
If you prefer to install manually.
- Clone Badgeable
- Copy
Badgeable.swift
file into your Xcode project. - That's it!
Add import
syntax where you would conform Badgeable
protocol.
import Badgeable
Conform Badgeable
protocol where you want to display badge.
// Conform Badgeable protocol in your class.
class YourButton: UIButton, Badgeable {
// ...
}
Then you can display badge by setting badgeCount
property.
class YourViewController: UIViewController {
@IBOutlet weak var button: YourButton!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
button.badgeCount = 6
}
}
You can conform Badgeable
protocol even UIView by extension.
// Conformance Badgeable into UIView
extension UIView: Badgeable {}
Then all UI components can display badge by setting badgeCount
property.
- Configurable badge appearance.
- Adjustable badge position. For example: TopLeft, TopRight, BottomLeft and BottomRight.
- Animatable.
Daniel (Dae Hyun) KIM, gwangpa@gmail.com
Badgeable is available under the MIT license. See the LICENSE file for more info.