SRMonthPicker.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. Copyright (C) 2012-2015 Simon Rice
  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. #ifndef IBInspectable
  21. #define IBInspectable
  22. #endif
  23. @class SRMonthPicker;
  24. /**
  25. Defines a set of optional methods you can use to receive change-related
  26. messages for SRMonthPicker objects. All of the methods in this protocol are
  27. optional. Typically, the delegate implements other optional methods to
  28. respond to new selections.
  29. */
  30. @protocol SRMonthPickerDelegate <NSObject>
  31. @optional
  32. /**
  33. Tells the delegate that a specified date is about to be selected.
  34. @param monthPicker A month picker object informing the delegate about the
  35. impending selection.
  36. */
  37. - (void)monthPickerWillChangeDate:(SRMonthPicker *)monthPicker;
  38. /**
  39. Tells the delegate that a specified date has been selected.
  40. @param monthPicker A month picker object informing the delegate about the
  41. committed selection.
  42. */
  43. - (void)monthPickerDidChangeDate:(SRMonthPicker *)monthPicker;
  44. @end
  45. /**
  46. The SRMonthPicker class implements an object that uses multiple rotating
  47. wheels to allow users to select a month and year. This is similar to both
  48. iOS's UIDatePicker set to Date-only mode without the day element and Mobile
  49. Safari's picker view that appears for an `<input type="month" />` tag.
  50. Unlike UIDatePicker, SRMonthPicker does inherit from UIPickerView. It does
  51. use both UIPickerViewDataSource and UIPickerViewDelegate, but presents a
  52. monthPickerDelegate property.
  53. */
  54. @interface SRMonthPicker : UIPickerView<UIPickerViewDataSource, UIPickerViewDelegate>
  55. /**
  56. The designated delegate for the month picker.
  57. @warning **Important:** The delegate property is already used internally for
  58. UIPickerView's delegate - **please don't read from or assign to it**!
  59. */
  60. @property (nonatomic, weak) id<SRMonthPickerDelegate> monthPickerDelegate;
  61. /**
  62. The date represented by the month picker.
  63. The day component is ignored when written, and set to 1 when read.
  64. */
  65. @property (nonatomic, strong) IBInspectable NSDate* date;
  66. /// The calendar currently being used
  67. @property (nonatomic, strong, readonly) NSCalendar *calendar;
  68. /// The minimum year that a month picker can show.
  69. @property (nonatomic) IBInspectable NSInteger minimumYear;
  70. /// The maximum year that a month picker can show.
  71. @property (nonatomic) IBInspectable NSInteger maximumYear;
  72. /// A Boolean value that determines whether the year is shown first.
  73. @property (nonatomic) IBInspectable BOOL yearFirst;
  74. /// A Boolean value that determines whether the month wraps
  75. @property (nonatomic) IBInspectable BOOL wrapMonths;
  76. /// A Boolean value that determines whether the current month & year are coloured.
  77. @property (nonatomic) BOOL enableColourRow;
  78. /// en-US alias for `enableColourRow`.
  79. @property (nonatomic, getter = enableColourRow, setter = setEnableColourRow:) IBInspectable BOOL enableColorRow;
  80. /// Font to be used for all rows. Default: System Bold, size 24.
  81. @property (nonatomic, strong) UIFont *font;
  82. /// Colour to be used for all "non coloured" rows. Default: Black.
  83. @property (nonatomic, strong) UIColor *fontColour;
  84. /// en-US alias for `fontColour`.
  85. @property (nonatomic, strong, getter = fontColour, setter = setFontColour:) IBInspectable UIColor *fontColor;
  86. /**
  87. Designated initialiser.
  88. Initializes and returns a newly allocated month picker with the current calendar,
  89. month & year.
  90. */
  91. -(id)init;
  92. /**
  93. Initializes and returns a newly allocated month picker with the specified
  94. date and current calendar.
  95. @param date The date to be represented by the month picker - the day
  96. component will be ignored.
  97. */
  98. -(id)initWithDate:(NSDate *)date;
  99. /**
  100. Initializes and returns a newly allocated month picker with the specified
  101. date and current calendar.
  102. @param date The date to be represented by the month picker - the day
  103. component will be ignored.
  104. @param calendar The calendar to used by the date.
  105. */
  106. -(id)initWithDate:(NSDate *)date calendar:(NSCalendar *)calendar;
  107. @end