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
.
API description
/**
The common dialog box style. It is the same as the system style but does not contain the blur background.
*/
@interface AUNoticeDialog : AUDialogBaseView
/**
The method of dialog box initialization without the button title.
@param title The title.
@param message The message details.
@return The AUNoticeDialog instance.
*/
- (instancetype)initWithTitle:(NSString *)title
message:(NSString *)message;
/**
The method of initializing the dialog box with the button title.
@param title The title.
@param message The message details.
@param delegate The AUDialogDelegate-compliant protocol object.
@param buttonTitle The button title list.
@return The AUNoticeDialog instance.
*/
- (instancetype)initWithTitle:(NSString *)title
message:(NSString *)message
delegate:(id<AUDialogDelegate>)delegate
buttonTitles:(NSString *)buttonTitle, ... NS_REQUIRES_NIL_TERMINATION;
- (instancetype)initWithCustomView:(UIView *)customView; // The custom view.
- (instancetype)init NS_UNAVAILABLE;
/**
The dialog box display method.
*/
- (void)show;
/**
Add a button and its callback method.
@param buttonTitle The button title.
@param actionBlock The callback of the button tapping action.
*/
- (void)addButton:(NSString *)buttonTitle actionBlock:(AUDialogActionBlock)actionBlock;
/**
The method of closing the dialog box. It is similar to the dismissWithClickedButtonIndex method of APAlertView.
*/
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
/**
Set the text alignment mode.
@param alignment The alignment mode.
*/
- (void)setMessageAlignment:(NSTextAlignment)alignment;
Add a new dialog box
Use the block to add a callback of the button tapping action.
AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"Title" message:@"Message details"]; [dialog addButton:@"Got it" actionBlock:^{ NSLog(@"print pressed") }]; [dialog addButton:@"OK" actionBlock:nil]; [dialog show];
Use the delegate to add a callback of the button tapping action.
AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithTitle:@"Title" message:@"Message details" delegate:delegate buttonTitles:@"OK", nil]; [dialog show]; The delegate protocol is AUDialogDelegate, similar to UIAlertViewDelegate.
Create a dialog box in a simple way.
NS_INLINE AUNoticeDialog *AUNoticeDialogWithTitle(NSString *title) 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.
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id<AUDialogDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle 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.
NS_INLINE UIAlertView *UIAlertViewWithTitleAndMessage(NSString *title, NSString *message) // NS_INLINE UIAlertView *UIAlertViewWithTitle(NSString *title) NS_INLINE UIAlertView *UIAlertViewWithMessage(NSString *message)
Use the addButtonWithTitle API that supports APAlertView to create a dialog box. No modification is required.
- (NSInteger)addButtonWithTitle:(NSString *)title callback:(void (^)(int index, NSString *title))callback; /** @brief Add a cancel button and its callback. @param title The button title. @param callback The callback. */ - (NSInteger)addCancelButtonWithTitle:(NSString *)title callback:(void (^)(int index, NSString *title))callback; /** @brief Add a button. @param title The button title. */ - (NSInteger)addButtonWithTitle:(NSString *)title; /** @brief Add a cancel button. @param title The button title. */ - (NSInteger)addCancelButtonWithTitle:(NSString *)title; +(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.
/** The method of closing the dialog box. It is similar to the dismissWithClickedButtonIndex method of APAlertView. */ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated - (nullable NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex; /** Specify the number of buttons. (It is similar to numberOfButtons of APAlertView.) */ @property(nonatomic,readonly) NSInteger numberOfButtons; /** The index of the cancel button. (It is similar to cancelButtonIndex of APAlertView.) */ @property(nonatomic) NSInteger cancelButtonIndex;
When you call the following APIs of APAlertView, you only need to change the method name.
Change the
showAlert
method toshow
.For example, change
[alertView showAlert]
to[alertView show]
.Change the
removeAllAlerviews
method todismissAll
.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.
NoteThe class file is AUInputDialog.h.
Use UIAlertController
Modify the creation method as follows:
[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert] Modified to: [[AUNoticeDialog alloc] initWithTitle:@"Title" message:@"Message details"]
Modify the button and callback addition method as follows:
[UIAlertAction actionWithTitle:title style:(UIAlertActionStyle)style handler:handler] Modified to: [dialog addButton:@"Got it" actionBlock:^{ NSLog(@"xxxx"); }]
Code sample
Standard style
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."] ; [dialog addButton:@"Got it" actionBlock:nil]; [dialog addButton:@"OK" actionBlock:nil]; [dialog show];
Custom style
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 60)]; customView.backgroundColor = [UIColor greenColor]; AUNoticeDialog *dialog = [[AUNoticeDialog alloc] initWithCustomView:customView]; [dialog addButton:@"Cancel" actionBlock:nil]; [dialog addButton:@"OK" actionBlock:nil]; [dialog show];