JSBadgeView.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright (c) 2013 Javier Soto.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #import <UIKit/UIKit.h>
  20. typedef NS_ENUM(NSUInteger, JSBadgeViewAlignment)
  21. {
  22. JSBadgeViewAlignmentTopLeft = 1,
  23. JSBadgeViewAlignmentTopRight,
  24. JSBadgeViewAlignmentTopCenter,
  25. JSBadgeViewAlignmentCenterLeft,
  26. JSBadgeViewAlignmentCenterRight,
  27. JSBadgeViewAlignmentBottomLeft,
  28. JSBadgeViewAlignmentBottomRight,
  29. JSBadgeViewAlignmentBottomCenter,
  30. JSBadgeViewAlignmentCenter
  31. };
  32. @interface JSBadgeView : UIView
  33. @property (nonatomic, copy) NSString *badgeText;
  34. #pragma mark - Customization
  35. @property (nonatomic, assign) JSBadgeViewAlignment badgeAlignment UI_APPEARANCE_SELECTOR;
  36. @property (nonatomic, strong) UIColor *badgeTextColor UI_APPEARANCE_SELECTOR;
  37. @property (nonatomic, assign) CGSize badgeTextShadowOffset UI_APPEARANCE_SELECTOR;
  38. @property (nonatomic, strong) UIColor *badgeTextShadowColor UI_APPEARANCE_SELECTOR;
  39. @property (nonatomic, strong) UIFont *badgeTextFont UI_APPEARANCE_SELECTOR;
  40. @property (nonatomic, strong) UIColor *badgeBackgroundColor UI_APPEARANCE_SELECTOR;
  41. /**
  42. * Color of the overlay circle at the top. Default is semi-transparent white.
  43. */
  44. @property (nonatomic, strong) UIColor *badgeOverlayColor UI_APPEARANCE_SELECTOR;
  45. /**
  46. * Color of the badge shadow. Default is semi-transparent black.
  47. */
  48. @property (nonatomic, strong) UIColor *badgeShadowColor UI_APPEARANCE_SELECTOR;
  49. /**
  50. * Offset of the badge shadow. Default is 3.0 points down.
  51. */
  52. @property (nonatomic, assign) CGSize badgeShadowSize UI_APPEARANCE_SELECTOR;
  53. /**
  54. * Width of the circle around the badge. Default is 2.0 points.
  55. */
  56. @property (nonatomic, assign) CGFloat badgeStrokeWidth UI_APPEARANCE_SELECTOR;
  57. /**
  58. * Color of the circle around the badge. Default is white.
  59. */
  60. @property (nonatomic, strong) UIColor *badgeStrokeColor UI_APPEARANCE_SELECTOR;
  61. /**
  62. * Allows to shift the badge by x and y points.
  63. */
  64. @property (nonatomic, assign) CGPoint badgePositionAdjustment UI_APPEARANCE_SELECTOR;
  65. /**
  66. * You can use this to position the view if you're drawing it using drawRect instead of `-addSubview:`
  67. * (optional) If not provided, the superview frame is used.
  68. */
  69. @property (nonatomic, assign) CGRect frameToPositionInRelationWith UI_APPEARANCE_SELECTOR;
  70. /**
  71. * The minimum width of a badge circle. We need this to avoid elipse shapes when using small fonts.
  72. */
  73. @property (nonatomic, assign) CGFloat badgeMinWidth UI_APPEARANCE_SELECTOR;
  74. /**
  75. * Optionally init using this method to have the badge automatically added to another view.
  76. */
  77. - (id)initWithParentView:(UIView *)parentView alignment:(JSBadgeViewAlignment)alignment;
  78. @end