Skip to content

Display badge icon to any subclass of UIView and UIBarButtonItem

License

Notifications You must be signed in to change notification settings

gwangpa/Badgeable

Repository files navigation

Badgeable

CI Status Version License Platform

Badgeable

Bedgeable is a protocol can display badge into your any custom UI components or even apply all UIView.

Requirements

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

CocoaPods

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

Carthage

Will support Carthage soon.

Manually

If you prefer to install manually.

  • Clone Badgeable
  • Copy Badgeable.swift file into your Xcode project.
  • That's it!

Usage

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.

TODO

  • Configurable badge appearance.
  • Adjustable badge position. For example: TopLeft, TopRight, BottomLeft and BottomRight.
  • Animatable.

Author

Daniel (Dae Hyun) KIM, gwangpa@gmail.com

License

Badgeable is available under the MIT license. See the LICENSE file for more info.

About

Display badge icon to any subclass of UIView and UIBarButtonItem

Resources

License

Stars

Watchers

Forks

Packages

No packages published