AHKActionSheet.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // AHKActionSheet.h
  3. // AHKActionSheetExample
  4. //
  5. // Created by Arkadiusz on 08-04-14.
  6. // Copyright (c) 2014 Arkadiusz Holko. All rights reserved.
  7. //
  8. // Modify by Marino Faggiana on 11/01/17.
  9. // Copyright (c) 2017 TWS. All rights reserved.
  10. //
  11. // Author Marino Faggiana <m.faggiana@twsweb.it>
  12. //
  13. #import <UIKit/UIKit.h>
  14. typedef NS_ENUM(NSInteger, AHKActionSheetButtonType) {
  15. AHKActionSheetButtonTypeDefault = 0,
  16. AHKActionSheetButtonTypeDisabled,
  17. AHKActionSheetButtonTypeDestructive,
  18. AHKActionSheetButtonTypeEncrypted
  19. };
  20. @class AHKActionSheet;
  21. typedef void(^AHKActionSheetHandler)(AHKActionSheet *actionSheet);
  22. /// A block-based alternative to the `UIAlertView`.
  23. @interface AHKActionSheet : UIView <UIAppearanceContainer>
  24. // Appearance - all of the following properties should be set before showing the action sheet. See `+initialize` to learn the default values of all properties.
  25. /**
  26. * See UIImage+AHKAdditions.h/.m to learn how these three properties are used.
  27. */
  28. @property (nonatomic) CGFloat blurRadius UI_APPEARANCE_SELECTOR;
  29. @property (strong, nonatomic) UIColor *blurTintColor UI_APPEARANCE_SELECTOR;
  30. @property (nonatomic) CGFloat blurSaturationDeltaFactor UI_APPEARANCE_SELECTOR;
  31. /// Height of the button (internally it's a `UITableViewCell`).
  32. @property (nonatomic) CGFloat buttonHeight UI_APPEARANCE_SELECTOR;
  33. /// Height of the cancel button.
  34. @property (nonatomic) CGFloat cancelButtonHeight UI_APPEARANCE_SELECTOR;
  35. /// Height separator from cancelButtonHeight and table
  36. @property (nonatomic) CGFloat separatorHeight UI_APPEARANCE_SELECTOR;
  37. /**
  38. * If set, a small shadow (a gradient layer) will be drawn above the cancel button to separate it visually from the other buttons.
  39. * It's best to use a color similar (but maybe with a lower alpha value) to blurTintColor.
  40. * See "Advanced" example in the example project to see it used.
  41. */
  42. /// Boxed (@YES, @NO) boolean value (enabled by default). Isn't supported on iOS 6.
  43. @property (strong, nonatomic) NSNumber *automaticallyTintButtonImages UI_APPEARANCE_SELECTOR;
  44. /// Boxed boolean value. Useful when adding buttons without images (in that case text looks better centered). Disabled by default.
  45. @property (strong, nonatomic) NSNumber *buttonTextCenteringEnabled UI_APPEARANCE_SELECTOR;
  46. /// Color of the separator between buttons.
  47. @property (strong, nonatomic) UIColor *separatorColor UI_APPEARANCE_SELECTOR;
  48. /// Text attributes of the title (passed in initWithTitle: or set via `title` property)
  49. @property (copy, nonatomic) NSDictionary *titleTextAttributes UI_APPEARANCE_SELECTOR;
  50. @property (copy, nonatomic) NSDictionary *buttonTextAttributes UI_APPEARANCE_SELECTOR;
  51. @property (copy, nonatomic) NSDictionary *disableButtonTextAttributes UI_APPEARANCE_SELECTOR;
  52. @property (copy, nonatomic) NSDictionary *destructiveButtonTextAttributes UI_APPEARANCE_SELECTOR;
  53. @property (copy, nonatomic) NSDictionary *encryptedButtonTextAttributes UI_APPEARANCE_SELECTOR;
  54. @property (copy, nonatomic) NSDictionary *cancelButtonTextAttributes UI_APPEARANCE_SELECTOR;
  55. /// Duration of the show/dismiss animations. Defaults to 0.5.
  56. @property (nonatomic) NSTimeInterval animationDuration UI_APPEARANCE_SELECTOR;
  57. /// Boxed boolean value. Enables/disables control hiding with pan gesture. Enabled by default.
  58. @property (strong, nonatomic) NSNumber *cancelOnPanGestureEnabled UI_APPEARANCE_SELECTOR;
  59. /// Boxed boolean value. Enables/disables control hiding when tapped on empty area. Disabled by default.
  60. @property (strong, nonatomic) NSNumber *cancelOnTapEmptyAreaEnabled UI_APPEARANCE_SELECTOR;
  61. /// A handler called on every type of dismissal (tapping on "Cancel" or swipe down or flick down).
  62. @property (strong, nonatomic) AHKActionSheetHandler cancelHandler;
  63. @property (copy, nonatomic) NSString *cancelButtonTitle;
  64. /// String to display above the buttons.
  65. @property (copy, nonatomic) NSString *title;
  66. /// View to display above the buttons (only if the title isn't set).
  67. @property (strong, nonatomic) UIView *headerView;
  68. /// Window visible before the actionSheet was presented.
  69. @property (weak, nonatomic, readonly) UIWindow *previousKeyWindow;
  70. /// View actionSheet was presented.
  71. @property (nonatomic, weak) UIView *view;
  72. /**
  73. * Initializes the action sheet with a specified title. `headerView` can be used if a string is insufficient for the title; set `title` as `nil` in this case.
  74. *
  75. * It's the designated initializer.
  76. *
  77. * @param title A string to display in the title area, above the buttons.
  78. *
  79. * @return A newly initialized action sheet.
  80. */
  81. - (instancetype)initWithTitle:(NSString *)title;
  82. /**
  83. * Initializes the action sheet with a specified view and title. `headerView` can be used if a string is insufficient for the title; set `title` as `nil` in this case.
  84. *
  85. * It's the designated initializer.
  86. *
  87. * @param view
  88. * @param title A string to display in the title area, above the buttons.
  89. *
  90. * @return A newly initialized action sheet.
  91. */
  92. - (instancetype)initWithView:(UIView *)view title:(NSString *)title;
  93. /**
  94. * Adds a button with an image. Has to be called before showing the action sheet.
  95. *
  96. * @param image The image to display on the left of the title.
  97. * @param handler A completion handler block to execute when a dismissal animation (after the user tapped on the button) has finished.
  98. */
  99. - (void)addButtonWithTitle:(NSString *)title image:(UIImage *)image backgroundColor:(UIColor *)backgroundColor height:(CGFloat)height type:(AHKActionSheetButtonType)type handler:(AHKActionSheetHandler)handler;
  100. /// Displays the action sheet.
  101. - (void)show;
  102. /// Dismisses the action sheet with an optional animation.
  103. - (void)dismissAnimated:(BOOL)animated;
  104. @end