美文网首页
iOS 小红点方案

iOS 小红点方案

作者: 豪冷 | 来源:发表于2018-09-04 17:31 被阅读53次

效果图:

UIButton 为例:

屏幕快照 2018-09-04 下午5.15.42 2.png

原理

  • 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;


仓库


其他

CSDN: https://me.csdn.net/xjh093

相关文章

网友评论

      本文标题:iOS 小红点方案

      本文链接:https://www.haomeiwen.com/subject/aoknwftx.html