#import <UIKit/UIKit.h>
@interface UIView (CHRRedDot)
@property (readonly, nonatomic) CALayer * chr_redDotLayer;
/**
红点圆心的位置,与各个边之间的距离。如果距离<=0,则忽略距离
*/
@property (nonatomic, assign) UIEdgeInsets chr_redDotEdgeInsets;
/**
红点的半径,默认为4
*/
@property (nonatomic, assign) CGFloat chr_redDotRadius;
/**
红点的颜色,默认为0xFF5A5A
*/
@property (nonatomic, strong) UIColor * chr_redDotColor;
/**
红点是否显示
*/
@property (nonatomic, assign) BOOL chr_redDotShow;
@end
#pragma mark - method
- (void)chr_updateRedDot {
CALayer *redDot = self.chr_redDotLayer;
if (self.chr_redDotShow) {
if (redDot == nil) {
redDot = [CALayer layer];
self.chr_redDotLayer = redDot;
[self.layer addSublayer:redDot];
}
redDot.backgroundColor = self.chr_redDotColor.CGColor;
[self chr_layoutRedDot];
} else {
[redDot removeFromSuperlayer];
self.chr_redDotLayer = nil;
}
}
- (void)chr_layoutRedDot {
CALayer *redDot = self.chr_redDotLayer;
if (redDot == nil) return;
CGFloat radius = self.chr_redDotRadius;
redDot.cornerRadius = radius;
UIEdgeInsets edgeInsets = self.chr_redDotEdgeInsets;
CGFloat originX = edgeInsets.right <= 0 ? edgeInsets.left - radius : self.bounds.size.width - edgeInsets.right + radius;
CGFloat originY = edgeInsets.bottom <= 0 ? edgeInsets.top - radius : self.bounds.size.height - edgeInsets.bottom + radius;
CGFloat length = radius * 2;
redDot.frame = CGRectMake(originX, originY, length, length);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有