效果图:
原理
- 给
写了一个分类 UIView
UIView+JHRedDot
- 在设置小红点时,监听
的 view
和 frame
,以便在bounds
尺寸变化时更新小红点位置view
- 重写系统函数
来设置小红点的初始位置- (void)willMoveToSuperview:(UIView *)newSuperview;
- 针对
做了进一步处理,自动靠右。UIButton
示例
button.frame = CGRectMake(0, 0, 34, 44);
button.jh_redDot = [JHRedDot redDotWithConfig:({
JHRedDotConfig *config = [[JHRedDotConfig alloc] init];
config.offsetY = 5;
config;
})];
button.jh_redDot.hidden = YES;
仓库
- github:https://github.com/xjh093/JHRedDot