AHKActionSheet.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. AHKActionSheetButtonTypeCrypto
  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. /**
  31. * If set, a small shadow (a gradient layer) will be drawn above the cancel button to separate it visually from the other buttons.
  32. * It's best to use a color similar (but maybe with a lower alpha value) to blurTintColor.
  33. * See "Advanced" example in the example project to see it used.
  34. */
  35. @property (strong, nonatomic) UIColor *cancelButtonShadowColor UI_APPEARANCE_SELECTOR;
  36. /// Boxed (@YES, @NO) boolean value (enabled by default). Isn't supported on iOS 6.
  37. @property (strong, nonatomic) NSNumber *automaticallyTintButtonImages UI_APPEARANCE_SELECTOR;
  38. /// Boxed boolean value. Useful when adding buttons without images (in that case text looks better centered). Disabled by default.
  39. @property (strong, nonatomic) NSNumber *buttonTextCenteringEnabled UI_APPEARANCE_SELECTOR;
  40. /// Color of the separator between buttons.
  41. @property (strong, nonatomic) UIColor *separatorColor UI_APPEARANCE_SELECTOR;
  42. /// Background color of the button when it's tapped (internally it's a UITableViewCell)
  43. @property (strong, nonatomic) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;
  44. /// Text attributes of the title (passed in initWithTitle: or set via `title` property)
  45. @property (copy, nonatomic) NSDictionary *titleTextAttributes UI_APPEARANCE_SELECTOR;
  46. @property (copy, nonatomic) NSDictionary *buttonTextAttributes UI_APPEARANCE_SELECTOR;
  47. @property (copy, nonatomic) NSDictionary *disabledButtonTextAttributes UI_APPEARANCE_SELECTOR;
  48. @property (copy, nonatomic) NSDictionary *destructiveButtonTextAttributes UI_APPEARANCE_SELECTOR;
  49. @property (copy, nonatomic) NSDictionary *cryptoButtonTextAttributes UI_APPEARANCE_SELECTOR;
  50. @property (copy, nonatomic) NSDictionary *cancelButtonTextAttributes UI_APPEARANCE_SELECTOR;
  51. /// Duration of the show/dismiss animations. Defaults to 0.5.
  52. @property (nonatomic) NSTimeInterval animationDuration UI_APPEARANCE_SELECTOR;
  53. /// Boxed boolean value. Enables/disables control hiding with pan gesture. Enabled by default.
  54. @property (strong, nonatomic) NSNumber *cancelOnPanGestureEnabled UI_APPEARANCE_SELECTOR;
  55. /// Boxed boolean value. Enables/disables control hiding when tapped on empty area. Disabled by default.
  56. @property (strong, nonatomic) NSNumber *cancelOnTapEmptyAreaEnabled UI_APPEARANCE_SELECTOR;
  57. /// A handler called on every type of dismissal (tapping on "Cancel" or swipe down or flick down).
  58. @property (strong, nonatomic) AHKActionSheetHandler cancelHandler;
  59. @property (copy, nonatomic) NSString *cancelButtonTitle;
  60. /// String to display above the buttons.
  61. @property (copy, nonatomic) NSString *title;
  62. /// View to display above the buttons (only if the title isn't set).
  63. @property (strong, nonatomic) UIView *headerView;
  64. /// Window visible before the actionSheet was presented.
  65. @property (weak, nonatomic, readonly) UIWindow *previousKeyWindow;
  66. ///TWS
  67. @property (nonatomic, weak) UIView *view;
  68. /**
  69. * 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.
  70. *
  71. * It's the designated initializer.
  72. *
  73. * @param title A string to display in the title area, above the buttons.
  74. *
  75. * @return A newly initialized action sheet.
  76. */
  77. - (instancetype)initWithTitle:(NSString *)title;
  78. - (instancetype)initWithView:(UIView *)view title:(NSString *)title;
  79. /**
  80. * Adds a button without an image. Has to be called before showing the action sheet.
  81. *
  82. * @param handler A completion handler block to execute when a dismissal animation (after the user tapped on the button) has finished.
  83. */
  84. - (void)addButtonWithTitle:(NSString *)title type:(AHKActionSheetButtonType)type handler:(AHKActionSheetHandler)handler;
  85. /**
  86. * Adds a button with an image. Has to be called before showing the action sheet.
  87. *
  88. * @param image The image to display on the left of the title.
  89. * @param handler A completion handler block to execute when a dismissal animation (after the user tapped on the button) has finished.
  90. */
  91. - (void)addButtonWithTitle:(NSString *)title image:(UIImage *)image type:(AHKActionSheetButtonType)type handler:(AHKActionSheetHandler)handler;
  92. /// Displays the action sheet.
  93. - (void)show;
  94. /// Dismisses the action sheet with an optional animation.
  95. - (void)dismissAnimated:(BOOL)animated;
  96. @end