酷店

UIView+BABadgeView.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*!
  2. * @header BAKit.h
  3. *
  4. * @brief BAKit
  5. *
  6. * @author 博爱
  7. * @copyright Copyright © 2016年 博爱. All rights reserved.
  8. * @version V1.0
  9. */
  10. // _ooOoo_
  11. // o8888888o
  12. // 88" . "88
  13. // (| -_- |)
  14. // O\ = /O
  15. // ____/`---'\____
  16. // . ' \\| |// `.
  17. // / \\||| : |||// \
  18. // / _||||| -:- |||||- \
  19. // | | \\\ - /// | |
  20. // | \_| ''\---/'' | |
  21. // \ .-\__ `-` ___/-. /
  22. // ___`. .' /--.--\ `. . __
  23. // ."" '< `.___\_<|>_/___.' >'"".
  24. // | | : `- \`.;`\ _ /`;.`/ - ` : | |
  25. // \ \ `-. \_ __\ /__ _/ .-` / /
  26. // ======`-.____`-.___\_____/___.-`____.-'======
  27. // `=---='
  28. //
  29. // .............................................
  30. // 佛祖镇楼 BUG辟易
  31. // 佛曰:
  32. // 一人 我编程累 累得只想把觉睡
  33. // 两眼 是辛酸泪 代码咋写都不对
  34. //
  35. // 重启是也不行 关机它也不灵
  36. // 我狂敲键盘怒砸鼠标 异常也不停
  37. //
  38. // 这循环它有点绕 注释也很微妙
  39. // 我看了半天稀里糊涂马隔壁我草
  40. //
  41. // 加断点 再抵坝 堆栈瞬间就爆炸
  42. // 日志输出如雨下 看到异常就害怕
  43. //
  44. // 调试一夜没人陪 心想这锅该归谁
  45. // 回想当初心后悔 不该重构这地雷
  46. //
  47. // 翻日志 看半天 博客看了几百篇
  48. // 闪退还是没复现 低头又点一根烟
  49. //
  50. // 加着班我心烦乱 烂摊子我不想干
  51. // 离职损失就几万 一拍桌子把工作换
  52. //
  53. // 离职 我不再忙 在家 我守空房
  54. // 我闲得无聊掏出电脑 代码又写几行
  55. /*
  56. *********************************************************************************
  57. *
  58. * 在使用 BAKit 的过程中如果出现 bug 请及时以以下任意一种方式联系我,我会及时修复 bug
  59. *
  60. * QQ : 可以添加ios开发技术群 479663605 在这里找到我(博爱1616【137361770】)
  61. * 微博 : 博爱1616
  62. * Email : 137361770@qq.com
  63. * GitHub : https://github.com/boai
  64. * BAHome : https://github.com/BAHome
  65. * 博客 : http://boaihome.com
  66. *********************************************************************************
  67. */
  68. // 源码:https://github.com/jkpang/PPBadgeView
  69. #import <UIKit/UIKit.h>
  70. @class BABadgeLabel;
  71. @interface UIView (BABadgeView)
  72. /**
  73. 添加带文本内容的Badge, 默认右上角, 红色, 18pts
  74. Add Badge with text content, the default upper right corner, red backgroundColor, 18pts
  75. */
  76. - (void)ba_addBadgeWithText:(NSString *)text;
  77. /**
  78. 添加带数字的Badge, 默认右上角,红色,18pts
  79. Add the Badge with numbers, the default upper right corner, red backgroundColor, 18pts
  80. */
  81. - (void)ba_addBadgeWithNumber:(NSInteger)number;
  82. /**
  83. 添加带颜色的小圆点, 默认右上角, 红色, 8pts
  84. Add small dots with color, the default upper right corner, red backgroundColor, 8pts
  85. */
  86. - (void)ba_addDotWithColor:(UIColor *)color;
  87. /**
  88. 设置Badge的高度,因为Badge宽度是动态可变的,通过改变Badge高度,其宽度也按比例变化,方便布局
  89. (注意: 此方法需要将Badge添加到控件上后再调用!!!)
  90. Set the height of Badge, because the Badge width is dynamically and  variable.
  91. By changing the Badge height in proportion to facilitate the layout.
  92. (Note: this method needs to add Badge to the controls and then use it !!!)
  93. @param points 高度大小
  94. */
  95. - (void)ba_setBadgeHeightPoints:(CGFloat)points;
  96. /**
  97. 设置Badge的偏移量, Badge中心点默认为其父视图的右上角
  98. Set Badge offset, Badge center point defaults to the top right corner of its parent view
  99. @param x X轴偏移量 (x<0: 左移, x>0: 右移) axis offset (x <0: left, x> 0: right)
  100. @param y Y轴偏移量 (y<0: 上移, y>0: 下移) axis offset ( Y <0: up, y> 0: down)
  101. */
  102. - (void)ba_moveBadgeWithX:(CGFloat)x Y:(CGFloat)y;
  103. /**
  104. 设置Bage的属性
  105. Set properties for Badge
  106. */
  107. - (void)ba_setBadgeLabelAttributes:(void(^)(BABadgeLabel *badgeLabel))attributes;
  108. /// 显示Badge
  109. - (void)ba_showBadge;
  110. /// 隐藏Badge
  111. - (void)ba_hiddenBadge;
  112. #pragma mark - 数字增加/减少, 注意:以下方法只适用于Badge内容为纯数字的情况
  113. /// Digital increase /decrease, note: the following method applies only to cases where the Badge content is purely numeric
  114. - (void)ba_increase;
  115. - (void)ba_increaseBy:(NSInteger)number;
  116. - (void)ba_decrease;
  117. - (void)ba_decreaseBy:(NSInteger)number;
  118. @end