MKNumberBadgeView.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // MKNumberBadgeView.h
  3. //
  4. // Copyright 2009-2012 Michael F. Kamprath
  5. // michael@claireware.com
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License");
  8. // you may not use this file except in compliance with the License.
  9. // You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. // See the License for the specific language governing permissions and
  17. // limitations under the License.
  18. //
  19. //
  20. // MKNumberBadgeView
  21. // -----------------
  22. //
  23. // Use this class to display a badge containing an integer value.Similar to the app icon badges that the iPhone OS permits.
  24. //
  25. // Notes:
  26. // * When creating the view, the frame used should be larger than the expected visual size of the badge view. Use the alignment
  27. // property to control the horizontal placement of the badge within the view's bounds. The badge will always be vertically
  28. // centered for the badge itself ignoring the size fo the shadow if it is enabled.
  29. // * The view's background color is automatically set to clear. If you change the background color, you may get curious results.
  30. //
  31. #import <UIKit/UIKit.h>
  32. @interface MKNumberBadgeView : UIView
  33. {
  34. NSUInteger _value;
  35. }
  36. // The current value displayed in the badge. Updating the value will update the view's display
  37. @property (assign,nonatomic) NSUInteger value;
  38. // Indicates whether the badge view draws a dhadow or not.
  39. @property (assign,nonatomic) BOOL shadow;
  40. // The offset for the shadow, if there is one.
  41. @property (assign,nonatomic) CGSize shadowOffset;
  42. // The base color for the shadow, if there is one.
  43. @property (retain,nonatomic) UIColor * shadowColor;
  44. // Indicates whether the badge view should be drawn with a shine
  45. @property (assign,nonatomic) BOOL shine;
  46. // The font to be used for drawing the numbers. NOTE: not all fonts are created equal for this purpose.
  47. // Only "system fonts" should be used.
  48. @property (retain,nonatomic) UIFont* font;
  49. // The color used for the background of the badge.
  50. @property (retain,nonatomic) UIColor* fillColor;
  51. // The color to be used for drawing the stroke around the badge.
  52. @property (retain,nonatomic) UIColor* strokeColor;
  53. // The width for the stroke around the badge.
  54. @property (assign,nonatomic) CGFloat strokeWidth;
  55. // The color to be used for drawing the badge's numbers.
  56. @property (retain,nonatomic) UIColor* textColor;
  57. // How the badge image hould be aligned horizontally in the view.
  58. @property (assign,nonatomic) NSTextAlignment alignment;
  59. // Returns the visual size of the badge for the current value. Not the same hing as the size of the view's bounds.
  60. // The badge view bounds should be wider than space needed to draw the badge.
  61. @property (readonly,nonatomic) CGSize badgeSize;
  62. // The number of pixels between the number inside the badge and the stroke around the badge. This value
  63. // is approximate, as the font geometry might effectively slightly increase or decrease the apparent pad.
  64. @property (nonatomic) NSUInteger pad;
  65. // If YES, the badge will be hidden when the value is 0
  66. @property (nonatomic) BOOL hideWhenZero;
  67. @property (nonatomic) BOOL iOS7;
  68. @end