AbstractActionSheetPicker.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. //Copyright (c) 2011, Tim Cinel
  3. //All rights reserved.
  4. //
  5. //Redistribution and use in source and binary forms, with or without
  6. //modification, are permitted provided that the following conditions are met:
  7. //* Redistributions of source code must retain the above copyright
  8. //notice, this list of conditions and the following disclaimer.
  9. //* Redistributions in binary form must reproduce the above copyright
  10. //notice, this list of conditions and the following disclaimer in the
  11. //documentation and/or other materials provided with the distribution.
  12. //* Neither the name of the <organization> nor the
  13. //names of its contributors may be used to endorse or promote products
  14. //derived from this software without specific prior written permission.
  15. //
  16. //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. //DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  20. //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. //
  27. #import <Foundation/Foundation.h>
  28. #import <UIKit/UIKit.h>
  29. @class SWActionSheet;
  30. #define SuppressPerformSelectorLeakWarning(Stuff) \
  31. do { \
  32. _Pragma("clang diagnostic push") \
  33. _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
  34. Stuff; \
  35. _Pragma("clang diagnostic pop") \
  36. } while (0)
  37. typedef NS_ENUM(NSInteger, ActionType) {
  38. ActionTypeValue,
  39. ActionTypeSelector,
  40. ActionTypeBlock
  41. };
  42. typedef NS_ENUM(NSInteger, TapAction) {
  43. TapActionNone,
  44. TapActionSuccess,
  45. TapActionCancel
  46. };
  47. typedef void (^ActionBlock)(void);
  48. static NSString *const kButtonValue = @"buttonValue";
  49. static NSString *const kButtonTitle = @"buttonTitle";
  50. static NSString *const kActionType = @"buttonAction";
  51. static NSString *const kActionTarget = @"buttonActionTarget";
  52. @interface AbstractActionSheetPicker : NSObject <UIPopoverControllerDelegate>
  53. @property(nonatomic, strong) SWActionSheet *actionSheet;
  54. @property (nonatomic) UIWindowLevel windowLevel;
  55. @property(nonatomic, assign) NSInteger tag;
  56. @property(nonatomic, assign) int borderWidth;
  57. @property(nonatomic, strong) UIToolbar *toolbar;
  58. @property(nonatomic, copy) NSString *title;
  59. @property(nonatomic, strong) UIView *pickerView;
  60. @property(nonatomic, readonly) CGSize viewSize;
  61. @property(nonatomic, strong) NSMutableArray *customButtons;
  62. @property(nonatomic, assign) BOOL hideCancel; // show or hide cancel button.
  63. @property(nonatomic, assign) CGRect presentFromRect;
  64. @property(nonatomic) NSDictionary *titleTextAttributes; // default is nil. Used to specify Title Label attributes.
  65. @property(nonatomic) NSAttributedString *attributedTitle; // default is nil. If titleTextAttributes not nil this value ignored.
  66. @property(nonatomic) NSMutableDictionary *pickerTextAttributes; // default with a NSMutableParagraphStyle to set label align center. Used to specify Picker Label attributes.
  67. @property(nonatomic) UIColor *pickerBackgroundColor;
  68. @property(nonatomic) UIColor *toolbarBackgroundColor;
  69. @property(nonatomic, strong) UIColor *toolbarButtonsColor;
  70. @property(nonatomic) NSNumber *pickerBlurRadius;
  71. @property(nonatomic, retain) Class popoverBackgroundViewClass; //allow popover customization on iPad
  72. @property(nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientations; // You can set your own supportedInterfaceOrientations value to prevent dismissing picker in some special cases.
  73. @property(nonatomic) TapAction tapDismissAction; // Specify, which action should be fired in case of tapping outside of the picker (on top darkened side). Default is TapActionNone.
  74. @property(nonatomic) BOOL popoverDisabled; // Disable popover behavior on iPad
  75. - (void)setTextColor:(UIColor *)textColor;
  76. // For subclasses.
  77. - (instancetype)initWithTarget:(id)target successAction:(SEL)successAction cancelAction:(SEL)cancelActionOrNil origin:(id)origin;
  78. // Present the ActionSheetPicker
  79. - (void)showActionSheetPicker;
  80. // For subclasses. This is used to send a message to the target upon a successful selection and dismissal of the picker (i.e. not canceled).
  81. - (void)notifyTarget:(id)target didSucceedWithAction:(SEL)successAction origin:(id)origin;
  82. // For subclasses. This is an optional message upon cancelation of the picker.
  83. - (void)notifyTarget:(id)target didCancelWithAction:(SEL)cancelAction origin:(id)origin;
  84. // For subclasses. This returns a configured picker view. Subclasses should autorelease.
  85. - (UIView *)configuredPickerView;
  86. // Adds custom buttons to the left of the UIToolbar that select specified values
  87. - (void)addCustomButtonWithTitle:(NSString *)title value:(id)value;
  88. // Adds custom buttons to the left of the UIToolbar that implement specified block
  89. - (void)addCustomButtonWithTitle:(NSString *)title actionBlock:(ActionBlock)block;
  90. // Adds custom buttons to the left of the UIToolbar that implement specified selector
  91. - (void)addCustomButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector;
  92. //For subclasses. This responds to a custom button being pressed.
  93. - (IBAction)customButtonPressed:(id)sender;
  94. // Allow the user to specify a custom cancel button
  95. - (void)setCancelButton:(UIBarButtonItem *)button;
  96. // Allow the user to specify a custom done button
  97. - (void)setDoneButton:(UIBarButtonItem *)button;
  98. // Hide picker programmatically
  99. - (void)hidePickerWithCancelAction;
  100. @end