AHKActionSheet.h 5.9 KB

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