All Products
Search
Document Center

Action sheet

Last Updated: May 25, 2021

AUActionSheet is migrated from APActionSheet. The style is slightly adjusted, supporting the common layout with the deletion button and the common sheet layout.

Sample images

  • Common layout with the delete button:

  • Tab layout:

  • Badges:

Dependency

The dependency of AUActionSheet is as follows:

 
  1. AntUI(iOS)
  2. 1.0.0.161108003457
  3. APCommonUI(iOS)
  4. 1.2.0.161108102201

API description

 
  1. typedef NS_ENUM(NSInteger, AUActionSheetButtonType) {
  2. AUActionSheetButtonTypeDefault = 0, // The default type.
  3. AUActionSheetButtonTypeDisabled, // The button cannot be tapped.
  4. AUActionSheetButtonTypeDestructive, // The red destructive button.
  5. AUActionSheetButtonTypeCustom // The customized type.
  6. };
  7. /**
  8. AUActionSheet The API is migrated from APActionSheet, and the style is adjusted.
  9. */
  10. @interface AUActionSheet: UIView<UIAppearanceContainer>
  11. /// The button height is 42 by default.
  12. @property (nonatomic) CGFloat buttonHeight UI_APPEARANCE_SELECTOR;
  13. /// The height of the Cancel button.
  14. @property (nonatomic) CGFloat cancelButtonHeight UI_APPEARANCE_SELECTOR;
  15. /// The color of the separation line, which is AU_COLOR_LINE by default.
  16. @property (strong, nonatomic) UIColor *separatorColor UI_APPEARANCE_SELECTOR;
  17. /// The background color of a tapped button.
  18. @property (strong, nonatomic) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;
  19. // The attributes of UI components.
  20. @property (copy, nonatomic) NSDictionary *titleTextAttributes UI_APPEARANCE_SELECTOR;
  21. @property (copy, nonatomic) NSDictionary *buttonTextAttributes UI_APPEARANCE_SELECTOR;
  22. @property (copy, nonatomic) NSDictionary *disabledButtonTextAttributes UI_APPEARANCE_SELECTOR;
  23. @property (copy, nonatomic) NSDictionary *destructiveButtonTextAttributes UI_APPEARANCE_SELECTOR;
  24. @property (copy, nonatomic) NSDictionary *cancelButtonTextAttributes UI_APPEARANCE_SELECTOR;
  25. /// The duration for showing or hiding an animation, which is 0.5s by default.
  26. @property (nonatomic) NSTimeInterval animationDuration UI_APPEARANCE_SELECTOR;
  27. /// The title.
  28. @property(nonatomic,copy) NSString *title;
  29. /// Whether the item is visible
  30. @property(nonatomic, readonly, getter=isVisible) BOOL visible;
  31. /// The header view of a custom button.
  32. @property (strong, nonatomic) UIView *headerView;
  33. /// The keyWindow before the ActionSheet instance is displayed.
  34. @property (weak, nonatomic, readonly) UIWindow *previousKeyWindow;
  35. /// The protocol delegate.
  36. @property(nonatomic,weak)id<UIActionSheetDelegate> delegate;
  37. /// The title of the Cancel button.
  38. @property (copy, nonatomic) NSString *cancelButtonTitle;
  39. /// The number of buttons.
  40. @property(nonatomic, readonly) NSInteger numberOfButtons;
  41. /// The index of the Cancel button, which is −1 by default.
  42. @property(nonatomic) NSInteger cancelButtonIndex;
  43. /// The index of a destructive red button, which is −1 by default and can be ignored if only one button exists.<UActionSheetButtonTypeDestructive, // The red destructive button.>
  44. @property(nonatomic) NSInteger destructiveButtonIndex;
  45. /**
  46. The AUActionSheet initialization method
  47. @param title The title information.
  48. @param delegate The delegate object.
  49. @param cancelButtonTitle The title of the Cancel button.
  50. @param destructiveButtonTitle The title of a destructive button.
  51. @param otherButtonTitles The list of other button title parameters.
  52. @return The AUActionSheet instance.
  53. */
  54. - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  55. /**
  56. The AUActionSheet initialization method.
  57. @param title The title information.
  58. @param delegate The delegate object.
  59. @param cancelButtonTitle The title of the Cancel button.
  60. @param destructiveButtonTitle The title of a destructive button.
  61. @param items The customOption data list (with custom title colors and badges).
  62. @return The AUActionSheet instance.
  63. */
  64. - (instancetype)initWithTitle:(NSString *)title
  65. delegate:(id<UIActionSheetDelegate>)delegate
  66. cancelButtonTitle:(NSString *)cancelButtonTitle
  67. destructiveButtonTitle:(NSString *)destructiveButtonTitle
  68. items:(NSArray<AUActionSheetItem *> *)items;
  69. /**
  70. Add a button of a default type.
  71. @param title The button title.
  72. @return The button index, starting from 0.
  73. */
  74. - (NSInteger)addButtonWithTitle:(NSString *)title;
  75. /**
  76. Add a button.
  77. @param title The button title.
  78. @param type The button type.
  79. @return The button index, starting from 0.
  80. */
  81. - (NSInteger)addButtonWithTitle:(NSString *)title type:(AUActionSheetButtonType)type;
  82. /**
  83. Obtain the button title based on the index.
  84. @param buttonIndex The button index.
  85. @return The button title.
  86. */
  87. - (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
  88. /**
  89. Set a button in a position.
  90. @param item The button type after information encapsulation.
  91. @param index The index of the button to be replaced. The index is less than the number of existing buttons.
  92. */
  93. - (void)setButton:(AUActionSheetItem *)item atIndex:(NSInteger)index;
  94. /** The ActionSheet display method. */
  95. - (void)show;
  96. /**
  97. Manually call the hiding method.
  98. @param animate Whether a hiding animation is available.
  99. */
  100. - (void)closeWithAnimate:(BOOL)animate;
  101. /**
  102. Manually simulate the hiding method based on button tapping (a protocol method related to button tapping is called back).
  103. @param buttonIndex The button index.
  104. @param animated Whether a hiding animation is available.
  105. */
  106. - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
  107. /**
  108. * Dynamically add an item.
  109. * Note: Call this method after the actionSheet is shown on the screen. To add a button before the action sheet is shown, use addButtonWithTitle.
  110. *
  111. * @param item The custom item.
  112. * @param index The position where the item is added.
  113. */
  114. - (void)addButton:(AUActionSheetItem *)item atIndex:(NSInteger)index;
  115. // Set the background mode. If the value is YES or @(YES), all displayed action sheets are hidden. The default value is NO.
  116. +(void)setIsBackGroundMode:(BOOL)isBackGroundMode;
  117. +(void)weakSetIsBackGroundMode:(id)isBackGroundMode;
  118. - (void)showFromToolbar:(UIToolbar *)view;
  119. - (void)showFromTabBar:(UITabBar *)view;
  120. - (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);
  121. - (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);
  122. - (void)showInView:(UIView *)view;
  123. @end
  124. /** The ActionSheet button class after encapsulation. */
  125. @interface AUActionSheetItem: NSObject
  126. /// The button title.
  127. @property (copy, nonatomic) NSString *title;
  128. /// The button type.
  129. @property (nonatomic) AUActionSheetButtonType type;
  130. /// The color of the button title. When you set this value, manually change the button type to AUActionSheetButtonTypeCustom.
  131. @property (strong,nonatomic) UIColor *titleColor;
  132. /**
  133. * Set the style for displaying badges .
  134. *
  135. * badgeValue: @"." A red dot is displayed.
  136. * @"new" "new" is displayed.
  137. * @"数字" A digit is displayed. If the digit is larger than 99, the more (...) image is displayed.
  138. * @"惠"/"hui" "惠" is displayed.
  139. * @"新" "新" is displayed.
  140. * nil Clear the displayed content.
  141. */
  142. @property (nonatomic, copy) NSString *badgeValue;
  143. @end

Code sample

  • Common layout with the delete button:
 
  1. AUActionSheet *actionSheet = [[AUActionSheet alloc] initWithTitle:@ "Provide one or two lines of comments for information classification."
  2. delegate:self
  3. cancelButtonTitle:@"Cancel"
  4. destructiveButtonTitle:@"Delete"
  5. otherButtonTitles:nil];
  6. [actionSheet show];
  • Tab layout:
 
  1. AUActionSheet *actionSheet = [[AUActionSheet alloc] initWithTitle:nil
  2. delegate:self
  3. cancelButtonTitle:@"Cancel"
  4. destructiveButtonTitle:nil
  5. otherButtonTitles:@"Option 1",@"Option 2",@"Option 3", nil];
  6. [actionSheet show];
  • Add a badge to an option:
 
  1. AUActionSheet *actionSheet = [[AUActionSheet alloc] initWithTitle:nil
  2. delegate:self
  3. cancelButtonTitle:@"Cancel"
  4. destructiveButtonTitle:nil
  5. otherButtonTitles:@"Option 1",@"Option 2",@"Option 3", nil];
  6. AUActionSheetItem *item = [[AUActionSheetItem alloc] init];
  7. item.title = @"Option 3";
  8. item.type = AUActionSheetButtonTypeCustom;
  9. item.badgeValue = @"new";
  10. item.titleColor = [UIColor redColor];
  11. [actionSheet setButton:item atIndex:2];
  12. [actionSheet show];