WZLBadgeProtocol.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // WZLBadgeProtocol.h
  3. // WZLBadgeDemo
  4. //
  5. // Created by zilin_weng on 15/8/12.
  6. // Copyright (c) 2015年 Weng-Zilin. All rights reserved.
  7. //
  8. //WZLBadgeProtocol is a protocol which any Class supported (such UIView and UIBarButtonItem) should confirm
  9. //At present, there are two classes support WZLBadge(UIView and UIBarButtonItem). However, there may be more classes to support. Thus, it is necessary to abstract a protocol. 20150812.
  10. #ifndef WZLBadgeDemo_WZLBadgeProtocol_h
  11. #define WZLBadgeDemo_WZLBadgeProtocol_h
  12. #pragma mark -- types definition
  13. #define kBadgeBreatheAniKey @"breathe"
  14. #define kBadgeRotateAniKey @"rotate"
  15. #define kBadgeShakeAniKey @"shake"
  16. #define kBadgeScaleAniKey @"scale"
  17. #define kBadgeBounceAniKey @"bounce"
  18. //key for associative methods during runtime
  19. static char badgeLabelKey;
  20. static char badgeBgColorKey;
  21. static char badgeFontKey;
  22. static char badgeTextColorKey;
  23. static char badgeAniTypeKey;
  24. static char badgeFrameKey;
  25. static char badgeCenterOffsetKey;
  26. static char badgeMaximumBadgeNumberKey;
  27. typedef NS_ENUM(NSUInteger, WBadgeStyle)
  28. {
  29. WBadgeStyleRedDot = 0, /* red dot style */
  30. WBadgeStyleNumber, /* badge with number */
  31. WBadgeStyleNew /* badge with a fixed text "new" */
  32. };
  33. typedef NS_ENUM(NSUInteger, WBadgeAnimType)
  34. {
  35. WBadgeAnimTypeNone = 0, /* without animation, badge stays still */
  36. WBadgeAnimTypeScale, /* scale effect */
  37. WBadgeAnimTypeShake, /* shaking effect */
  38. WBadgeAnimTypeBounce, /* bouncing effect */
  39. WBadgeAnimTypeBreathe /* breathing light effect, which makes badge more attractive */
  40. };
  41. #pragma mark -- protocol definition
  42. @protocol WZLBadgeProtocol <NSObject>
  43. @required
  44. @property (nonatomic, strong) UILabel *badge; /* badge entity, which is adviced not to set manually */
  45. @property (nonatomic, strong) UIFont *badgeFont; /* [UIFont boldSystemFontOfSize:9] by default if not set */
  46. @property (nonatomic, strong) UIColor *badgeBgColor; /* red color by default if not set */
  47. @property (nonatomic, strong) UIColor *badgeTextColor; /* white color by default if not set */
  48. @property (nonatomic, assign) CGRect badgeFrame; /* we have optimized the badge frame and center.
  49. This property is adviced not to set manually */
  50. @property (nonatomic, assign) CGPoint badgeCenterOffset;/* offset from right-top corner. {0,0} by default */
  51. /* For x, negative number means left offset
  52. For y, negative number means bottom offset */
  53. @property (nonatomic, assign) WBadgeAnimType aniType; /* NOTE that this is not animation type of badge's
  54. appearing, nor hidding*/
  55. @property (nonatomic, assign) NSInteger badgeMaximumBadgeNumber; /*for WBadgeStyleNumber style badge,
  56. if badge value is above badgeMaximumBadgeNumber,
  57. "badgeMaximumBadgeNumber+" will be printed. */
  58. /**
  59. * show badge with red dot style and WBadgeAnimTypeNone by default.
  60. */
  61. - (void)showBadge;
  62. /**
  63. * showBadge
  64. *
  65. * @param style WBadgeStyle type
  66. * @param value (if 'style' is WBadgeStyleRedDot or WBadgeStyleNew,
  67. this value will be ignored. In this case, any value will be ok.)
  68. * @param aniType
  69. */
  70. - (void)showBadgeWithStyle:(WBadgeStyle)style
  71. value:(NSInteger)value
  72. animationType:(WBadgeAnimType)aniType;
  73. /**
  74. * clear badge
  75. */
  76. - (void)clearBadge;
  77. @end
  78. #endif