IQActionSheetPickerView.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // IQActionSheetPickerView.h
  3. // https://github.com/hackiftekhar/IQActionSheetPickerView
  4. // Copyright (c) 2013-14 Iftekhar Qurashi.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. #import <UIKit/UIKit.h>
  24. #import "IQActionSheetToolbar.h"
  25. #if !(__has_feature(objc_instancetype))
  26. #define instancetype id
  27. #endif
  28. /**
  29. Action Sheet style settings.
  30. `IQActionSheetPickerStyleTextPicker`
  31. Show pickerView with provided text data.
  32. `IQActionSheetPickerStyleDatePicker`
  33. Show UIDatePicker.
  34. */
  35. typedef NS_ENUM(NSUInteger, IQActionSheetPickerStyle) {
  36. IQActionSheetPickerStyleTextPicker,
  37. IQActionSheetPickerStyleDatePicker,
  38. IQActionSheetPickerStyleDateTimePicker,
  39. IQActionSheetPickerStyleTimePicker,
  40. };
  41. /// These keys are used to set text attributes for both `Cancel` and `Done` toolbar buttons.
  42. /// Identifies an attributed string of the toolbar button title for normal state.
  43. extern NSString * _Nonnull const kIQActionSheetAttributesForNormalStateKey;
  44. /// Identifies an attributed string of the toolbar button title for highlighted state.
  45. extern NSString * _Nonnull const kIQActionSheetAttributesForHighlightedStateKey;
  46. @class IQActionSheetPickerView;
  47. /*!
  48. ActionSheetPickerView delegate.
  49. */
  50. @protocol IQActionSheetPickerViewDelegate <NSObject>
  51. @optional
  52. - (void)actionSheetPickerView:(nonnull IQActionSheetPickerView *)pickerView didSelectTitles:(nonnull NSArray<NSString*>*)titles;
  53. - (void)actionSheetPickerView:(nonnull IQActionSheetPickerView *)pickerView didSelectDate:(nonnull NSDate*)date;
  54. - (void)actionSheetPickerView:(nonnull IQActionSheetPickerView *)pickerView didChangeRow:(NSInteger)row inComponent:(NSInteger)component;
  55. - (void)actionSheetPickerViewDidCancel:(nonnull IQActionSheetPickerView *)pickerView;
  56. - (void)actionSheetPickerViewWillCancel:(nonnull IQActionSheetPickerView *)pickerView;
  57. @end
  58. /*!
  59. ActionSheet style UIPickerView
  60. */
  61. @interface IQActionSheetPickerView : UIControl
  62. /*!
  63. Initialization method with a title for toolbar and a callback delegate
  64. */
  65. - (nonnull instancetype)initWithTitle:(nullable NSString *)title delegate:(nullable id<IQActionSheetPickerViewDelegate>)delegate;
  66. /*!
  67. delegate(weak reference) object to inform about the selected values in pickerView. Delegate method will be called on Done click.
  68. */
  69. @property(nullable, nonatomic, weak) id<IQActionSheetPickerViewDelegate> delegate;
  70. /*!
  71. actionSheetPickerStyle to show in picker. Default is IQActionSheetPickerStyleTextPicker.
  72. */
  73. @property(nonatomic, assign) IQActionSheetPickerStyle actionSheetPickerStyle; //
  74. @property(nonatomic,strong) IQActionSheetToolbar * _Nullable actionToolbar;
  75. /*!
  76. Color for toolBar
  77. */
  78. @property(nullable, nonatomic, strong) UIColor *toolbarTintColor UI_APPEARANCE_SELECTOR;
  79. /*!
  80. Color for buttons
  81. */
  82. @property(nullable, nonatomic, strong) UIColor *toolbarButtonColor UI_APPEARANCE_SELECTOR;
  83. /*!
  84. A dictionary containing the attributed strings of the cancel button for normal and highlighted states.
  85. */
  86. @property(nullable, nonatomic, strong) NSDictionary<NSString*,id> *cancelButtonAttributes UI_APPEARANCE_SELECTOR;
  87. /*!
  88. A dictionary containing the attributed strings of the done button for normal and highlighted states.
  89. */
  90. @property(nullable, nonatomic, strong) NSDictionary<NSString*,id> *doneButtonAttributes UI_APPEARANCE_SELECTOR;
  91. ///----------------------
  92. /// @name Show / Hide
  93. ///----------------------
  94. /*!
  95. Show picker view with slide up animation.
  96. */
  97. -(void)show;
  98. /*!
  99. Show picker view with slide up animation, completion block will be called on animation completion.
  100. */
  101. -(void)showWithCompletion:(nullable void (^)(void))completion;
  102. /*!
  103. Dismiss picker view with slide down animation.
  104. */
  105. -(void)dismiss;
  106. /*!
  107. Dismiss picker view with slide down animation, completion block will be called on animation completion.
  108. */
  109. -(void)dismissWithCompletion:(nullable void (^)(void))completion;
  110. ///-----------------------------------------
  111. /// @name IQActionSheetPickerStyleTextPicker
  112. ///-----------------------------------------
  113. /*!
  114. selected titles for each component. Please use [ NSArray of NSString ] format. (Not Animated)
  115. */
  116. @property(nullable, nonatomic, strong) NSArray<NSString*> *selectedTitles;
  117. /*!
  118. set selected titles for each component. Please use [ NSArray of NSString ] format.
  119. */
  120. -(void)setSelectedTitles:(nonnull NSArray<NSString*> *)selectedTitles animated:(BOOL)animated;
  121. /*!
  122. Titles to show for component. Please use [ NSArray(numberOfComponents) of [ NSArray of NSString ](RowValueForEachComponent)] format, even there is single row to show, For example.
  123. @[ @[ @"1", @"2", @"3", ], @[ @"11", @"12", @"13", ], @[ @"21", @"22", @"23", ]].
  124. */
  125. @property(nullable, nonatomic, strong) NSArray<NSArray<NSString*> *> *titlesForComponents;
  126. /*!
  127. Width to adopt for each component. Please use [NSArray of NSNumber] format. If you don't want to specify a row width then use @(0) to calculate row width automatically.
  128. */
  129. @property(nullable, nonatomic, strong) NSArray<id> *widthsForComponents;
  130. /*!
  131. Font for the UIPickerView components
  132. */
  133. @property(nullable, nonatomic, strong) UIFont *pickerComponentsFont UI_APPEARANCE_SELECTOR;
  134. /*!
  135. Background color for the `UIPickerView`
  136. */
  137. @property(nullable, nonatomic, strong) UIColor *pickerViewBackgroundColor UI_APPEARANCE_SELECTOR;
  138. /*!
  139. * Color for the UIPickerView
  140. */
  141. @property(nullable, nonatomic, strong) UIColor *pickerComponentsSelectColor UI_APPEARANCE_SELECTOR;
  142. @property(nullable, nonatomic, strong) UIColor *pickerComponentsColor UI_APPEARANCE_SELECTOR;
  143. @property(nullable, nonatomic, strong) UIColor *lineColor;
  144. @property(nonatomic, assign) CGSize lineSize;
  145. @property(nonatomic,assign)BOOL clickBackHide;
  146. @property(nonatomic,strong)UIColor* pickBkgColor;
  147. /*!
  148. Font for the UIToolBar title
  149. */
  150. @property(nullable, nonatomic, strong) UIFont *titleFont UI_APPEARANCE_SELECTOR;
  151. /*!
  152. * Color for the UIToolBar title
  153. */
  154. @property(nullable, nonatomic, strong) UIColor *titleColor UI_APPEARANCE_SELECTOR;
  155. /*!
  156. Select the provided index row for each component. Please use [ NSArray of NSNumber ] format for indexes. Ignore if actionSheetPickerStyle is IQActionSheetPickerStyleDatePicker.
  157. */
  158. -(void)selectIndexes:(nonnull NSArray<NSNumber*> *)indexes animated:(BOOL)animated;
  159. /*!
  160. If YES then it will force to scroll third picker component to pick equal or larger row then the first.
  161. */
  162. @property(nonatomic, assign) BOOL isRangePickerView;
  163. /*!
  164. Reload a component in pickerView.
  165. */
  166. -(void)reloadComponent:(NSInteger)component;
  167. /*!
  168. Reload all components in pickerView.
  169. */
  170. -(void)reloadAllComponents;
  171. ///-------------------------------------------------------------------------------------------------------------------
  172. /// @name IQActionSheetPickerStyleDatePicker/IQActionSheetPickerStyleDateTimePicker/IQActionSheetPickerStyleTimePicker
  173. ///-------------------------------------------------------------------------------------------------------------------
  174. /*!
  175. selected date. Can also be use as setter method (not animated).
  176. */
  177. @property(nullable, nonatomic, assign) NSDate *date; //get/set date.
  178. /*!
  179. set selected date.
  180. */
  181. -(void)setDate:(nonnull NSDate *)date animated:(BOOL)animated;
  182. /*!
  183. Minimum selectable date in UIDatePicker. Default is nil.
  184. */
  185. @property (nullable, nonatomic, retain) NSDate *minimumDate;
  186. /*!
  187. Maximum selectable date in UIDatePicker. Default is nil.
  188. */
  189. @property (nullable, nonatomic, retain) NSDate *maximumDate;
  190. @end