Git Product home page Git Product logo

bbbadgebarbuttonitem's Introduction

BBBadgeBarButtonItem

Create a BarButtonItem with a badge on top. Easily customizable. Your BarButtonItem can be any custom view you wish for. The badge on top can display any number or string of any size or length.

ScreenShot BarButtonItem

How To Get Started

Installation with CocoaPods

Use the CocoaPods magic by adding in your podfile the following line :

pod 'BBBadgeBarButtonItem'

Manually

It's quite easy, just download and add "BBBadgeBarButtonItem.h" and "BBBadgeBarButtonItem.m" into your xcodeproject. Don't forget to import the header file wherever you need it :

#import "BBBadgeBarButtonItem.h"

Usage

Then, you only need to instantiate your beautiful BBBadgeBarButtonItem and add it to your navigation bar :

UIButton *customButton = [[UIButton alloc] init];
//...

// Create and add our custom BBBadgeBarButtonItem
BBBadgeBarButtonItem *barButton = [[BBBadgeBarButtonItem alloc] initWithCustomUIButton:customButton];
// Set a value for the badge
barButton.badgeValue = @"1";

// Add it as the leftBarButtonItem of the navigation bar
self.navigationItem.leftBarButtonItem = barButton;

If you want your BarButtonItem to handle touch event and click, use a UIButton as customView. The icon or text displayed by the BarButtonItem is your custom view.

Useful properties

Take a look at BBBadgeBarButtonItem.h to see how easily and quickly you can customize the badge. Remember that each time you change one of these value, the badge will directly be refresh to handle your styling preferences.

// Each time you change one of properties, the badge will refresh with your changes

// Badge value to be display
@property (nonatomic) NSString *badgeValue;
// Badge background color
@property (nonatomic) UIColor *badgeBGColor;
// Badge text color
@property (nonatomic) UIColor *badgeTextColor;
// Badge font
@property (nonatomic) UIFont *badgeFont;

// Padding value for the badge
@property (nonatomic) CGFloat badgePadding;
// Minimum size badge to small
@property (nonatomic) CGFloat badgeMinSize;
// Values for offseting the badge over the BarButtonItem you picked
@property (nonatomic) CGFloat badgeOriginX;
@property (nonatomic) CGFloat badgeOriginY;

// In case of numbers, remove the badge when reaching zero
@property BOOL shouldHideBadgeAtZero;
// Badge has a bounce animation when value changes
@property BOOL shouldAnimateBadge;

You can also choose to turn off the little bounce animation triggered when changing the badge value or decide if 0 should be display or not.

What else ?

The class is compatible with iOS >= 6.0.

There is a little demo project to help you if you need ;)

More

Any suggestions are welcome ! as I am looking to learn good practices, to understand better behaviors and Objective-C in general ! Thank you.

bbbadgebarbuttonitem's People

Contributors

dennisreimann avatar tanguyaladenise avatar

Watchers

 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.