文档

提示弹窗

更新时间:

AUNoticeDialog 为普通对话框样式,参考自系统 AlertView 但是不带 blur 背景。对话框的 Window 层级逻辑为 self.windowLevel = UIWindowLevelAlert - 1

效果图

接口说明

 /**
 普通 Dialog ,同系统样式不带 blur 背景
 */
@interface AUNoticeDialog : AUDialogBaseView

/**
 不带按钮标题的初始化方法。

 @param title 标题
 @param message 消息内容
 @return AUNoticeDialog 实例
 */
- (instancetype)initWithTitle:(NSString *)title
                                            message:(NSString *)message;

/**
 带按钮标题的初始化方法。

 @param title 标题
 @param message 消息内容
 @param delegate 协议对象(遵循 AUDialogDelegate)
 @param buttonTitle 按钮标题列表
 @return AUNoticeDialog 实例
 */
- (instancetype)initWithTitle:(NSString *)title
                                            message:(NSString *)message
                                        delegate:(id<AUDialogDelegate>)delegate
                                buttonTitles:(NSString *)buttonTitle, ... NS_REQUIRES_NIL_TERMINATION;

- (instancetype)initWithCustomView:(UIView *)customView; // 自定义内容区域

- (instancetype)init NS_UNAVAILABLE;

/**
 Dialog 展示方法。
 */
- (void)show;

/**
 添加按钮以及其回调方法。

 @param buttonTitle 按钮标题
 @param actionBlock 按钮点击回调
 */
- (void)addButton:(NSString *)buttonTitle actionBlock:(AUDialogActionBlock)actionBlock;

/**
  Dialog 消失方法,类似 APAlertView 的 dismissWithClickedButtonIndex 方法
  */
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

/**
  设置文本对齐
  @param alignment 对齐参数
  */
- (void)setMessageAlignment:(NSTextAlignment)alignment;

全新接入

  • 使用 block 添加 button 点击回调:

      AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"标题" message:@"内容"];
      [dialog addButton:@"知道了" actionBlock:^{
          NSLog(@"print pressed");
      }];
      [dialog addButton:@"好的" actionBlock:nil];
      [dialog show];
  • 使用 delegate 添加 button 点击回调:

      AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"标题" message:@"内容" delegate:delegate buttonTitles:@"确定", nil];
      [dialog show];
    
      delegate 协议为 AUDialogDelegate(类似 UIAlertViewDelegate)
  • 简便方法接入:

      NS_INLINE AUNoticeDialog *AUNoticeDialogWithTitle(NSString *title)
      NS_INLINE AUNoticeDialog *AUNoticeDialogWithTitleAndMessage(NSString *title, NSString *message)

APAlertView 与 UIAlertView 接入

以前主要为 APAlertView 和 UIAlertView,本节介绍如何更改为 AUNoticeDialog。

为了更简单的从 APAlertView 和 UIAlertView 接入 AUNoticeDialog,大部分接口均做了支持,因此大多数情况下只需要更改类名即可,具体如下:

  • AUNoticeDialog 支持 APAlertView 的创建接口。

- (instancetype)initWithTitle:(NSString *)title
                      message:(NSString *)message
                     delegate:(id<AUDialogDelegate>)delegate
            cancelButtonTitle:(NSString *)cancelButtonTitle
            otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;

创建时,更改类名即可,只需将 [[APAlertView alloc] initWithxxxxxx] 改为 [[AUNoticeDialog alloc] initWithxxxxxx]

  • 使用如下方法创建 UIAlertView,无需更改,因为接口中已做了更改。

NS_INLINE UIAlertView *UIAlertViewWithTitleAndMessage(NSString *title, NSString *message)
//
NS_INLINE UIAlertView *UIAlertViewWithTitle(NSString *title)
NS_INLINE UIAlertView *UIAlertViewWithMessage(NSString *message)
  • 支持 APAlertView 的 addButtonWithTitle 接口,接入时 无需更改

- (NSInteger)addButtonWithTitle:(NSString *)title callback:(void (^)(int index, NSString *title))callback;

/**
 @brief 添加取消 Button 和回调
 @param title 按钮 title
 @param callback 回调的 callback
 */
- (NSInteger)addCancelButtonWithTitle:(NSString *)title callback:(void (^)(int index, NSString *title))callback;

/**
 @brief 添加 Button
 @param title 按钮 title
 */
- (NSInteger)addButtonWithTitle:(NSString *)title;

/**
 @brief 添加取消 button
 @param title 按钮 title
 */
- (NSInteger)addCancelButtonWithTitle:(NSString *)title;

+(void)setBackgroundMode:(BOOL)isBackMode;
  • 使用如下 UIAlertView 方法也 无需更改,AUNoticeDialog 有同名方法支持。

/**
Dialog 消失方法,类似 APAlertView 的 dismissWithClickedButtonIndex 方法
*/
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
- (nullable NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
/**
 有多少个按钮(类似 APAlertView 的 numberOfButtons)
 */
@property(nonatomic,readonly) NSInteger numberOfButtons;

/**
 取消按钮的 index(类似 APAlertView 的 cancelButtonIndex)
 */
@property(nonatomic) NSInteger cancelButtonIndex;
  • 调用 APAlertView 的如下接口需要变更为其他方法,只需更改方法名

    • showAlert 方法改为 show 方法。

      例如:将 [alertView showAlert] 方法改为 [alertView show] 方法。

    • removeAllAlerviews 方法改为 dismissAll 方法。

      例如:[APAlertView removeAllAlerviews] 方法改为 [AUNoticeDialog dismissAll] 方法。

  • 如果使用了 APAlertView 或者 UIAlertView 的输入框功能,请使用 AUInputDialog 替换,使用方法与 AUNoticeDialog 基本相同。

    说明

    类文件为 AUInputDialog.h。

UIAlertController 接入

  • 创建方法修改,例如:

      [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]
      修改为
      [[AUNoticeDialog alloc] initWithTitle:@"标题" message:@"内容"]
  • 添加 button 和事件修改:

      [UIAlertAction actionWithTitle:title style:(UIAlertActionStyle)style handler:handler] 
      修改为 
      [dialog addButton:@"知道了" actionBlock:^{
          NSLog(@"xxxx");
      }]

代码示例

  • 标准样式:

      AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"标准控件" message:@"两个平台的同类控件命名需完全一样,控件命名以\"AU\"为前缀,控件自定义属性全部采用驼峰命名。注意:某些控件可能存在平台差别,一个平台需要实现另外一个平台不需要实现。"];
      [dialog addButton:@"知道了" actionBlock:nil];
      [dialog addButton:@"好的" actionBlock:nil];
      [dialog show];
  • 自定义样式:

      UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 60)];
      customView.backgroundColor = [UIColor greenColor];
    
      AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithCustomView:customView];
      [dialog addButton:@"取消" actionBlock:nil];
      [dialog addButton:@"确定" actionBlock:nil];
      [dialog show];
  • 本页导读 (0)
文档反馈