Skip to content
🌠 A simple category for you to add a badge to any UIView
Objective-C Shell Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example
Screenshots
Sources
.gitignore
.swift-version
CKBadgeView.podspec
LICENSE
README.md

README.md

CKBadgeView

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;
You can’t perform that action at this time.