A simple category for you to add a badge to any UIView.
Just one line of code, then you can add a badge to any UIView.
[view addBadge];Note: when calling the
addBadgemethod, a dynamic property named "badgeLayer" will be added to theviewinstance, please make sure yourUIViewclass did not contains any property with the same name.
and remote the badge with another line:
[view removeBadge];Add the following line to your Podfile
pod 'CKBadgeView'and run:
pod installDrag UIView+Badge.h and UIView+Badge.m to your xcode project
Adding a badge to the UIView is super simple.
#import <CKBadgeView/UIView+Badge.h>// 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;