All Products
Search
Document Center

Notification dialog

Last Updated: May 25, 2021

AUNoticeDialog specifies the style of a common dialog box. It references AlertView but does not contain the blur background. The Window level of the dialog box follows the logic self.windowLevel = UIWindowLevelAlert - 1.

Sample images

API description

 
  1. /**
  2. The common dialog box style. It is the same as the system style but does not contain the blur background.
  3. */
  4. @interface AUNoticeDialog : AUDialogBaseView
  5. /**
  6. The method of dialog box initialization without the button title.
  7. @param title The title.
  8. @param message The message details.
  9. @return The AUNoticeDialog instance.
  10. */
  11. - (instancetype)initWithTitle:(NSString *)title
  12. message:(NSString *)message;
  13. /**
  14. The method of initializing the dialog box with the button title.
  15. @param title The title.
  16. @param message The message details.
  17. @param delegate The AUDialogDelegate-compliant protocol object.
  18. @param buttonTitle The button title list.
  19. @return The AUNoticeDialog instance.
  20. */
  21. - (instancetype)initWithTitle:(NSString *)title
  22. message:(NSString *)message
  23. delegate:(id<AUDialogDelegate>)delegate
  24. buttonTitles:(NSString *)buttonTitle, ... NS_REQUIRES_NIL_TERMINATION;
  25. - (instancetype)initWithCustomView:(UIView *)customView; // The custom view.
  26. - (instancetype)init NS_UNAVAILABLE;
  27. /**
  28. The dialog box display method.
  29. */
  30. - (void)show;
  31. /**
  32. Add a button and its callback method.
  33. @param buttonTitle The button title.
  34. @param actionBlock The callback of the button tapping action.
  35. */
  36. - (void)addButton:(NSString *)buttonTitle actionBlock:(AUDialogActionBlock)actionBlock;
  37. /**
  38. The method of closing the dialog box. It is similar to the dismissWithClickedButtonIndex method of APAlertView.
  39. */
  40. - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
  41. /**
  42. Set the text alignment mode.
  43. @param alignment The alignment mode.
  44. */
  45. - (void)setMessageAlignment:(NSTextAlignment)alignment;

Add a new dialog box

  • Use the block to add a callback of the button tapping action.

       
    1. AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"Title" message:@"Message details"];
    2. [dialog addButton:@"Got it" actionBlock:^{
    3. NSLog(@"print pressed")
    4. }];
    5. [dialog addButton:@"OK" actionBlock:nil];
    6. [dialog show];
  • Use the delegate to add a callback of the button tapping action.

       
    1. AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"Title" message:@"Message details" delegate:delegate buttonTitles:@"OK", nil];
    2. [dialog show];
    3. The delegate protocol is AUDialogDelegate, similar to UIAlertViewDelegate.
  • Create a dialog box in a simple way.

       
    1. NS_INLINE AUNoticeDialog *AUNoticeDialogWithTitle(NSString *title)
    2. NS_INLINE AUNoticeDialog *AUNoticeDialogWithTitleAndMessage(NSString *title, NSString *message)

Use APAlertView and UIAlertView

This section describes how to modify APAlertView and UIAlertView to AUNoticeDialog.

Most APIs of AUNoticeDialog support APAlertView and UIAlertView. In most cases, you may only need to modify the class name. The detailed operations are as follows:

  • Use an API of AUNoticeDialog that supports APAlertView to create a dialog box.

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

    Change the class name from [[APAlertView alloc] initWithxxxxxx] to [[AUNoticeDialog alloc] initWithxxxxxx].

  • Use the following method to create UIAlertView. No modification is required, because relevant modification has been added to the API.

       
    1. NS_INLINE UIAlertView *UIAlertViewWithTitleAndMessage(NSString *title, NSString *message)
    2. //
    3. NS_INLINE UIAlertView *UIAlertViewWithTitle(NSString *title)
    4. NS_INLINE UIAlertView *UIAlertViewWithMessage(NSString *message)
  • Use the addButtonWithTitle API that supports APAlertView to create a dialog box. No modification is required.

       
    1. - (NSInteger)addButtonWithTitle:(NSString *)title callback:(void (^)(int index, NSString *title))callback;
    2. /**
    3. @brief Add a cancel button and its callback.
    4. @param title The button title.
    5. @param callback The callback.
    6. */
    7. - (NSInteger)addCancelButtonWithTitle:(NSString *)title callback:(void (^)(int index, NSString *title))callback;
    8. /**
    9. @brief Add a button.
    10. @param title The button title.
    11. */
    12. - (NSInteger)addButtonWithTitle:(NSString *)title;
    13. /**
    14. @brief Add a cancel button.
    15. @param title The button title.
    16. */
    17. - (NSInteger)addCancelButtonWithTitle:(NSString *)title;
    18. +(void)setBackgroundMode:(BOOL)isBackMode;
  • Use the following method of UIAlertView to create a dialog box. No modification is required. AUNoticeDialog has a method of the same name.

       
    1. /**
    2. The method of closing the dialog box. It is similar to the dismissWithClickedButtonIndex method of APAlertView.
    3. */
    4. - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
    5. - (nullable NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
    6. /**
    7. Specify the number of buttons. (It is similar to numberOfButtons of APAlertView.)
    8. */
    9. @property(nonatomic,readonly) NSInteger numberOfButtons;
    10. /**
    11. The index of the cancel button. (It is similar to cancelButtonIndex of APAlertView.)
    12. */
    13. @property(nonatomic) NSInteger cancelButtonIndex;
  • When you call the following APIs of APAlertView, you only need to change the method name.

    • Change the showAlert method to show.

      For example, change [alertView showAlert] to [alertView show].

    • Change the removeAllAlerviews method to dismissAll.

      For example, change [APAlertView removeAllAlerviews] to [AUNoticeDialog dismissAll].

  • To use the input box feature of APAlertView or UIAlertView, replace the corresponding methods with those of AUInputDialog. The operations are the same as those of AUNoticeDialog.

    Note:The class file is AUInputDialog.h.

Use UIAlertController

  • Modify the creation method as follows:

       
    1. [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]
    2. Modified to:
    3. [[AUNoticeDialog alloc] initWithTitle:@"Title" message:@"Message details"]
  • Modify the button and callback addition method as follows:

       
    1. [UIAlertAction actionWithTitle:title style:(UIAlertActionStyle)style handler:handler]
    2. Modified to:
    3. [dialog addButton:@"Got it" actionBlock:^{
    4. NSLog(@"xxxx");
    5. }]

Code sample

  • Standard style

       
    1. AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"Standard control" message:@"The controls of the same type must have the same name on two platforms. The prefix in a control name is \"AU\". Custom properties of a control are named in the camel-case format. Note: Some controls may be implemented in one platform but not in the other platform."] ;
    2. [dialog addButton:@"Got it" actionBlock:nil];
    3. [dialog addButton:@"OK" actionBlock:nil];
    4. [dialog show];
  • Custom style

       
    1. UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 60)];
    2. customView.backgroundColor = [UIColor greenColor];
    3. AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithCustomView:customView];
    4. [dialog addButton:@"Cancel" actionBlock:nil];
    5. [dialog addButton:@"OK" actionBlock:nil];
    6. [dialog show];