Latest 0.0.1
Homepage https://github.com/enix223/CKBadgeView
License MIT
Platforms ios 6.0, requires ARC
Frameworks QuartzCore
Authors

A simple category for you to add a badge to any UIView.

screenshot

Just one line of code, then you can add a badge to any UIView.

[view addBadge];

Note: when calling the addBadge method, a dynamic property named "badgeLayer" will be added to the view instance, please make sure your UIView class did not contains any property with the same name.

and remote the badge with another line:

[view removeBadge];

Installation

Cocoapods

Add the following line to your Podfile

pod 'CKBadgeView'

and run:

pod install

Manually

Drag UIView+Badge.h and UIView+Badge.m to your xcode project

Usage

Adding a badge to the UIView is super simple.

1. include the header file

#import <CKBadgeView/UIView+Badge.h>

2. call addBadge method to add a red badge

// Add a red badge with default values
[view addBadge];

The Badge category contains a set of addBadge methods for you to add badge with different requirement.

Add a red badge without offset

- (void)addBadge;

Add a red badge with given offset.

- (void)addBadgeWithOffset:(CGPoint)offset;

Add a badge to the UIView with given badge color.

- (void)addBadgeWithColor:(UIColor *)color;

Add a badge to the UIView with given content and color. (Default Setting: badge radius = 5, offset = CGPointZero)

- (void)addBadgeWithContent:(NSString *)content
                 badgeColor:(UIColor *)color;

Add a badge to the UIView with given content, color and offset.
(Default Setting: badge radius = 10, content font = HelveticaNeue, font size = 12.0)

- (void)addBadgeWithContent:(NSString *)content
                 badgeColor:(UIColor *)color
                     offset:(CGPoint)offset;

Add a badge to the UIView with customized settings.
(Default Setting: content font = HelveticaNeue, content font size = 12.0, content color = [UIColor whiteColor])

- (void)addBadgeWithContent:(NSString * _Nullable)content
                 badgeColor:(UIColor * _Nullable)color
                     offset:(CGPoint)offset
                badgeRadius:(CGFloat)badgeRadius;

Add a badge to the UIView with customized settings.

- (void)addBadgeWithContent:(NSString * _Nullable)content
                contentFont:(UIFont * _Nullable)contentFont
               contentColor:(UIColor * _Nullable)contentColor
                 badgeColor:(UIColor * _Nullable)color
                     offset:(CGPoint)offset
                badgeRadius:(CGFloat)badgeRadius;

Remove the badge from the UIView

- (void)removeBadge;

Latest podspec

{
    "name": "CKBadgeView",
    "version": "0.0.1",
    "summary": "A lightweight extension to add badge for UIView",
    "description": "CKBadgeView is an OBJC category for user to add badge to a UIView. nIt is easy to use, and just one line of code, then you can add a badge with default behaviour.",
    "homepage": "https://github.com/enix223/CKBadgeView",
    "license": "MIT",
    "authors": {
        "Enix Yu": "[email protected]"
    },
    "platforms": {
        "ios": "6.0"
    },
    "source": {
        "git": "https://github.com/enix223/CKBadgeView.git",
        "tag": "0.0.1"
    },
    "source_files": [
        "Sources",
        "Sources/**/*.{h,m}"
    ],
    "exclude_files": "Sources/Exclude",
    "frameworks": "QuartzCore",
    "requires_arc": true
}

Pin It on Pinterest

Share This