Skip to content

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

License

Notifications You must be signed in to change notification settings

enix223/CKBadgeView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published