説明なし

WZLBadgeProtocol.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. static char badgeRadiusKey;
  28. typedef NS_ENUM(NSUInteger, WBadgeStyle)
  29. {
  30. WBadgeStyleRedDot = 0, /* red dot style */
  31. WBadgeStyleNumber, /* badge with number */
  32. WBadgeStyleNew /* badge with a fixed text "new" */
  33. };
  34. typedef NS_ENUM(NSUInteger, WBadgeAnimType)
  35. {
  36. WBadgeAnimTypeNone = 0, /* without animation, badge stays still */
  37. WBadgeAnimTypeScale, /* scale effect */
  38. WBadgeAnimTypeShake, /* shaking effect */
  39. WBadgeAnimTypeBounce, /* bouncing effect */
  40. WBadgeAnimTypeBreathe /* breathing light effect, which makes badge more attractive */
  41. };
  42. #pragma mark -- protocol definition
  43. @protocol WZLBadgeProtocol <NSObject>
  44. @required
  45. @property (nonatomic, strong) UILabel *badge; /* badge entity, which is adviced not to set manually */
  46. @property (nonatomic, strong) UIFont *badgeFont; /* [UIFont boldSystemFontOfSize:9] by default if not set */
  47. @property (nonatomic, strong) UIColor *badgeBgColor; /* red color by default if not set */
  48. @property (nonatomic, strong) UIColor *badgeTextColor; /* white color by default if not set */
  49. @property (nonatomic, assign) CGRect badgeFrame; /* we have optimized the badge frame and center.
  50. This property is adviced not to set manually */
  51. @property (nonatomic, assign) CGPoint badgeCenterOffset; /* offset from right-top corner. {0,0} by default */
  52. /* For x, negative number means left offset
  53. For y, negative number means bottom offset */
  54. @property (nonatomic, assign) WBadgeAnimType aniType; /* NOTE that this is not animation type of badge's
  55. appearing, nor hidding*/
  56. @property (nonatomic, assign) NSInteger badgeMaximumBadgeNumber; /*for WBadgeStyleNumber style badge,
  57. if badge value is above badgeMaximumBadgeNumber,
  58. "badgeMaximumBadgeNumber+" will be printed. */
  59. @property (nonatomic, assign) CGFloat badgeRadius;
  60. // nomal use for red dot style of badge
  61. /**
  62. * show badge with red dot style and WBadgeAnimTypeNone by default.
  63. */
  64. - (void)showBadge;
  65. /**
  66. * showBadge
  67. *
  68. * @param style WBadgeStyle type
  69. * @param value (if 'style' is WBadgeStyleRedDot or WBadgeStyleNew,
  70. this value will be ignored. In this case, any value will be ok.)
  71. * @param aniType
  72. */
  73. - (void)showBadgeWithStyle:(WBadgeStyle)style
  74. value:(NSInteger)value
  75. animationType:(WBadgeAnimType)aniType;
  76. /**
  77. * clear badge
  78. */
  79. - (void)clearBadge;
  80. @end
  81. #endif