全部产品
云市场

选项卡

更新时间:2019-09-26 18:38:05

AUActionSheet 迁移自 APActionSheet,样式稍有调整,支持普通带删除按钮外观以及普通选项按钮外观。

效果图

  • 带删除按钮:

  • 选项卡按钮:

  • 红点:

依赖

AUActionSheet 的依赖如下:

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

接口说明

  1. typedef NS_ENUM(NSInteger, AUActionSheetButtonType) {
  2. AUActionSheetButtonTypeDefault = 0, // 默认
  3. AUActionSheetButtonTypeDisabled, // 不可点击
  4. AUActionSheetButtonTypeDestructive, // 红色删除性按钮
  5. AUActionSheetButtonTypeCustom // 自定义
  6. };
  7. /**
  8. AUAction Sheet,接口迁移自 APActionSheet,展示样式做了一些调整
  9. */
  10. @interface AUActionSheet : UIView<UIAppearanceContainer>
  11. /// 按钮高度 默认为 42
  12. @property (nonatomic) CGFloat buttonHeight UI_APPEARANCE_SELECTOR;
  13. /// 取消按钮高度
  14. @property (nonatomic) CGFloat cancelButtonHeight UI_APPEARANCE_SELECTOR;
  15. /// 分割线颜色 默认为 AU_COLOR_LINE
  16. @property (strong, nonatomic) UIColor *separatorColor UI_APPEARANCE_SELECTOR;
  17. /// 按钮点击背景色
  18. @property (strong, nonatomic) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;
  19. // UI 组件的一些 Attributes
  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. /// 显示隐藏动画时间,默认为 0.5
  26. @property (nonatomic) NSTimeInterval animationDuration UI_APPEARANCE_SELECTOR;
  27. /// 标题
  28. @property(nonatomic,copy) NSString *title;
  29. /// 是否已经展示
  30. @property(nonatomic, readonly, getter=isVisible) BOOL visible;
  31. /// 自定义按钮上方顶部视图
  32. @property (strong, nonatomic) UIView *headerView;
  33. /// ActionSheet 实例显示前的 keyWindow
  34. @property (weak, nonatomic, readonly) UIWindow *previousKeyWindow;
  35. /// 协议代理
  36. @property(nonatomic,weak)id<UIActionSheetDelegate> delegate;
  37. /// 取消按钮标题
  38. @property (copy, nonatomic) NSString *cancelButtonTitle;
  39. /// 按钮个数
  40. @property(nonatomic, readonly) NSInteger numberOfButtons;
  41. /// 取消按钮索引,默认为 -1
  42. @property(nonatomic) NSInteger cancelButtonIndex;
  43. /// 破坏性红色按钮索引值,默认为 -1,如果只有一个按钮则忽略。
  44. @property(nonatomic) NSInteger destructiveButtonIndex;
  45. /**
  46. AUActionSheet 初始化方法
  47. @param title 标题信息
  48. @param delegate 代理对象
  49. @param cancelButtonTitle 取消按钮标题
  50. @param destructiveButtonTitle 破坏性按钮标题
  51. @param otherButtonTitles 其他按钮标题参数列表
  52. @return AUActionSheet 实例
  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. AUActionSheet 初始化方法
  57. @param title 标题信息
  58. @param delegate 代理对象
  59. @param cancelButtonTitle 取消按钮标题
  60. @param destructiveButtonTitle 破坏性按钮标题
  61. @param items customOption数据列表(自定义 titleColor,红点)
  62. @return AUActionSheet 实例
  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. 增加一个按钮, 类型为默认类型
  71. @param title 按钮标题
  72. @return 按钮索引值,从 0 起
  73. */
  74. - (NSInteger)addButtonWithTitle:(NSString *)title;
  75. /**
  76. 增加一个按钮
  77. @param title 按钮标题
  78. @param type 按钮类型
  79. @return 按钮索引值,从 0 起
  80. */
  81. - (NSInteger)addButtonWithTitle:(NSString *)title type:(AUActionSheetButtonType)type;
  82. /**
  83. 通过索引值获取按钮标题
  84. @param buttonIndex 按钮索引值
  85. @return 按钮标题
  86. */
  87. - (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
  88. /**
  89. 设置某个位置的按钮
  90. @param item 封装信息后的按钮类型
  91. @param index 需要替换的索引值,小于现有按钮个数
  92. */
  93. - (void)setButton:(AUActionSheetItem *)item atIndex:(NSInteger)index;
  94. /** ActionSheet 展示方法 */
  95. - (void)show;
  96. /**
  97. 手动调用隐藏方法
  98. @param animate 隐藏是否带动画
  99. */
  100. - (void)closeWithAnimate:(BOOL)animate;
  101. /**
  102. 手动模拟按钮点击隐藏方法(会回调按钮点击相关的协议方法)
  103. @param buttonIndex 按钮索引
  104. @param animated 隐藏是否带动画
  105. */
  106. - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
  107. /**
  108. * 动态添加 item
  109. * 注意:请在 actionSheet show 出来后并显示在屏幕时调用;如需在 show 前 addButton,请使用 addButtonWithTitle
  110. *
  111. * @param item 自定义 item
  112. * @param index 添加的位置
  113. */
  114. - (void)addButton:(AUActionSheetItem *)item atIndex:(NSInteger)index;
  115. // 设置后台模式,如果为 YES 或者 @(YES) 则隐藏所有已经展示的 ActionSheet。默认为 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. /** 封装后的 ActionSheet 按钮类 */
  125. @interface AUActionSheetItem : NSObject
  126. /// 按钮标题
  127. @property (copy, nonatomic) NSString *title;
  128. /// 按钮的类型
  129. @property (nonatomic) AUActionSheetButtonType type;
  130. /// 按钮标题颜色,如果设置该值,请手动将按钮类型调整为 AUActionSheetButtonTypeCustom
  131. @property (strong,nonatomic) UIColor *titleColor;
  132. /**
  133. * 设置显示“红点”样式
  134. *
  135. * badgeValue: @"." 显示红点
  136. * @"new" 显示 new
  137. * @"数字" 显示数字,大于 99 则显示图片 more(...)
  138. * @"惠"/"hui" 显示“惠”字
  139. * @"xin" 显示"新"字
  140. * nil 清除当前显示
  141. */
  142. @property (nonatomic, copy) NSString *badgeValue;
  143. @end

代码示例

  • 带删除按钮:

    1. AUActionSheet *actionSheet = [[AUActionSheet alloc] initWithTitle:@"这是提供一行或二行注释, 通过信息澄清的方式避免用户产生疑问"
    2. delegate:self
    3. cancelButtonTitle:@"取消"
    4. destructiveButtonTitle:@"确认删除"
    5. otherButtonTitles:nil];
    6. [actionSheet show];
  • 选项卡按钮:

    1. AUActionSheet *actionSheet = [[AUActionSheet alloc] initWithTitle:nil
    2. delegate:self
    3. cancelButtonTitle:@"取消"
    4. destructiveButtonTitle:nil
    5. otherButtonTitles:@"选项一",@"选项二",@"选项三", nil];
    6. [actionSheet show];
  • 设置某个选项添加红点:

    1. AUActionSheet *actionSheet = [[AUActionSheet alloc] initWithTitle:nil
    2. delegate:self
    3. cancelButtonTitle:@"取消"
    4. destructiveButtonTitle:nil
    5. otherButtonTitles:@"选项一",@"选项二",@"选项三", nil];
    6. AUActionSheetItem *item = [[AUActionSheetItem alloc] init];
    7. item.title = @"选项三";
    8. item.type = AUActionSheetButtonTypeCustom;
    9. item.badgeValue = @"new";
    10. item.titleColor = [UIColor redColor];
    11. [actionSheet setButton:item atIndex:2];
    12. [actionSheet show];