Coder Social home page Coder Social logo

badgebarbuttonitem's Introduction

BadgeBarButtonItem

This is a porting to Xamarin.iOS Unified API of BBBadgeBarButtonItem by Tanguy Aladenise

This class creates an easily customizable BarButtonItem with a badge on top. The BarButtonItem can be any custom view and the badge can display numbers or strings.

ScreenShot BarButtonItem

How To Get Started

Just drop the BadgeBarButtonItem.cs file into your project and you're ready to go. Add a using Utility; directive in your code or change the namespace in the BadgeBarButtonItem.cs file to suite your needs.

Usage

You only need to instantiate the BadgeBarButtonItem and add it to your navigation bar:

UIButton customButton = new UIButton();
//...

// Create and add our custom BadgeBarButtonItem
BadgeBarButtonItem barButton = new BBBadgeBarButtonItem(customButton);
// Set a value for the badge
barButton.badgeValue = @"1";

// Add it as the RightBarButtonItem of the navigation bar
this.NavigationItem.RightBarButtonItem = barButton;

If you want the BarButtonItem to handle touch events, use a UIButton as customView.

Public properties

Take a look at BadgeBarButtonItem.cs to see how easily and quickly you can customize the badge. Remember that each time you change one of these value, the badge will be refreshed to display your changes.

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

// Badge value
public string BadgeValue { get; set; }

// Badge background color.
public UIColor BadgeBGColor { get; set; }

// Badge text color.
public UIColor BadgeTextColor { get; set; }

// Badge border color.
public UIColor BadgeBorderColor { get; set; }

// Badge font.
public UIFont BadgeFont { get; set; }

// Padding value for the badge.
public nfloat BadgePadding { get; set; }

// Minimum size of the badge minimum.
public nfloat BadgeMinSize { get; set; }

// X value for offsetting the badge over the BarButtonItem.
public nfloat BadgeOriginX { get; set; }

// Y value for offseting the badge over the BarButtonItem.
public nfloat BadgeOriginY { get; set; }

// Width of the border.
public nfloat BadgeBorderWidth { get; set; }

// Value indicating whether the badge should be removed when reaching zero.
public bool ShouldHideBadgeAtZero { get; set; }

// Value indicating whether the badge should be animated when its value changes.
public bool ShouldAnimateBadge { get; set; }

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

To do

Add support for tint color.

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.