效果图:
以 UIButton
为例:

原理
-
给
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;
网友评论