Giter Site home page Giter Site logo

uiviewbadge's Introduction

UIViewBadge

In many situatio, we need add a "red point" or "number with red background color" as a badge in an icon, to tell user---hey, there's something new here....
UIViewBadge is to solve this problem. It's an UIView extension in Swift, if you can find a UIView, you can easily add a badge to it. UIViewBadge only supported on iOS > 8 because Swift only support uses dynamic frameworks. As a result, if you want to support iOS < 8, download the code and copy the file to your project.

Example thunmbnail:
image

Install

pod 'UIViewBadge'

Usage In Swift

```swift```` //red point/number in UIButton aButton.setBadgeHidden(false) aButton.setBadgeStyle(BadgeStyle.Point(CGSizeMake(10, 10))) aButton.setBadgeBackgroundColor(UIColor.purpleColor())

    //red point/number in UIView
    aView.setBadgeHidden(false)
    aView.setBadgeBackgroundColor(UIColor.redColor())
    aView.setBadgeFontColor(UIFont.systemFontOfSize(10))
    aView.setBadgeStyle(BadgeStyle.Number(90000))
    
    //red point/number in UITabBar
    //    self.tabBarItem.badgeValue = "2";
    let view = self.tabBarController?.tabBar.viewInTabbarAtIndex(0)
    view?.backgroundColor = UIColor.yellowColor()
    view?.setBadgeHidden(false)
    view?.setBadgeStyle(BadgeStyle.Point(CGSizeMake(12, 12)))
    view?.setBadgeBackgroundColor(UIColor.purpleColor())
    
    //red point/number in UIBarButtonItem in UINavigationBar
    let navigationItem = self.tabBarController?.navigationItem
    navigationItem?.rightBarButtonItem = UIBarButtonItem(customView: self.buildACustomButton())
    navigationItem?.rightBarButtonItem?.customView?.setBadgeHidden(false)
    navigationItem?.rightBarButtonItem?.customView?.setBadgeStyle(BadgeStyle.Point(CGSizeMake(10, 10)))
    navigationItem?.rightBarButtonItem?.customView?.setBadgeBackgroundColor(UIColor.purpleColor())
    
    //red point/number in UIBarButtonItem in UITabBar
    let item:UIBarButtonItem = UIBarButtonItem(customView: self.buildACustomButton())
    aToolBar.items = [item]
    item.customView?.setBadgeHidden(false)
    item.customView?.setBadgeStyle(BadgeStyle.Point(CGSizeMake(10, 10)))
    item.customView?.setBadgeBackgroundColor(UIColor.purpleColor())
## Usage In Objective-C
```objective-c
    [_aButton setBadgeHidden:NO];
    [_aButton setPointBadge:CGSizeMake(10, 10)];
    [_aButton setBadgeBackgroundColor:[UIColor purpleColor]];
    
    [_aView setBadgeHidden:NO];
    [_aView setNumberBadge:9000];
    [_aView setBadgeBackgroundColor:[UIColor purpleColor]];
    
    UINavigationItem *navigationItem = self.tabBarController.navigationItem;
    navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[self buildACustomButton]];
    [navigationItem.rightBarButtonItem.customView setBadgeHidden:NO];
    [navigationItem.rightBarButtonItem.customView setPointBadge:CGSizeMake(10, 10)];
    [navigationItem.rightBarButtonItem.customView setBadgeBackgroundColor:[UIColor purpleColor]];

##Example Project An example project is provided. It requires IOS7 and can be run on device or simulator. This will work for any device size.

##Creator Goodyboy6

##License GBSwipeTableViewCell is available under the MIT license. See the LICENSE file for more info.

uiviewbadge's People

Contributors

goodyboy6 avatar

Watchers

James Cloos avatar peterwang avatar  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.