Giter Site home page Giter Site logo

badgecontrol's Introduction

defaultboomall

BadgeControl

  • Simply attach BadgeController to any UIView's subclasses and easily control the badge.
  • Customize size, position, background color, text color, border width, border color and animation of the badge.

Setup

Setup with CocoaPods (iOS 9+)

  • If you are using CocoaPods add this text to your Podfile and run pod install.
    pod 'BadgeControl'

Add source (iOS 9+)

Usage

Add import BadgeControl to your source code (unless you used the file setup method).

Simply attach BadgeController to your UIView (or its subclass).

let badge = BadgeController(for: myUIView)

Add an empty badge and present it with animation.

badge.addOrReplaceCurrent(animated: true)

Add a badge with text and present it with animation.

badge.addOrReplaceCurrent(with text: "1", animated: true)

Remove badge from its view.

badge.remove(animated: true)

Simply increment or decrement the value on your badge (if it is numeric) and present it with animation.

badge.increment(animated: true)
badge.decrement(animated: true)

You can also set animateOnlyWhenBadgeIsNotYetPresent = true if you don't want animation when badge is already present on the view.

Customization

You can customize badge's text font, background color, text color, border width, border color, size, center position and animation.

Text font, background color, text color, border width, border color and size

badge.badgeTextFont = UIFont.systemFont(ofSize: 15)
badge.badgeBackgroundColor = UIColor.blue
badge.badgeTextColor = UIColor.yellow
badge.borderWidth = 3 // in px
badge.borderColor = UIColor.black // black is default
badge.badgeHeight = 20 // badge will have height of 20px

Center position

You can choose following center positions: upperLeftCorner, upperRightCorner, lowerLeftCorner, lowerRightCorner.

You can also choose custom position by calling .custom(x: Double, y: Double).

badge.centerPosition = .upperLeftCorner
badge.centerPosition = .custom(x: 10, y: 20)

Animations

You can choose one of the following animations:

Default animation

default

badge.animation = BadgeAnimations.default
Left-right animation

default

badge.animation = BadgeAnimations.leftRight
Right-left animation

default

badge.animation = BadgeAnimations.rightLeft
Fade in animation

default

badge.animation = BadgeAnimations.fadeIn
Rolling animation

default

badge.animation = BadgeAnimations.rolling
Custom

You can also provide your own animation of type ((UIView) -> Void).

badge.animation = { badgeView in
    ...
  }

Initialization

You can use this initalizer with default values:

public init(for view: UIView,
            in centerPosition: BadgeCenterPosition = .upperRightCorner,
            badgeBackgroundColor: UIColor = .red,
            badgeTextColor: UIColor = .white,
            badgeTextFont: UIFont? = nil,
            borderWidth: CGFloat = 0.0,
            borderColor: UIColor = .black,
            animation: ((UIView) -> Void)? = BadgeAnimations.defaultAnimation,
            badgeHeight: Int? = nil
            animateOnlyWhenBadgeIsNotYetPresent: Bool = false)

License

BadgeControl is released under the MIT License.

Feedback is welcome

If you've found a bug or want to improve BadgeControl feel free to create an issue.

badgecontrol's People

Contributors

rkrenecky avatar jansvancer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.