iOS 小红点方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xjh093/article/details/82387268

效果图:

UIButton 为例:
这里写图片描述


原理

  • UIView写了一个分类 UIView+JHRedDot

  • 在设置小红点时,监听 viewframebounds,以便在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;

仓库

猜你喜欢

转载自blog.csdn.net/xjh093/article/details/82387268
今日推荐