A customized AlertView and ActionSheet
LGAlertSheet includes customized AlertView and ActionSheet.
Four kinds of AlertViews are implemented:
-
Normal AlertView with title, message and button(s);
-
AlertView with an image on the top;
-
AlertView with a TextField in it;
-
AlertView showing a progress view and optionally transitioning to completion state.
Two kinds of ActionSheet are implemented: ActionSheet with 1 option and with 2 options.
LGAlertSheet pretty much covers most of the usage scenarios and, moreover:
-
Easy to customize UI as it is implemented using xib and Autolayout.
-
Fully optimized for device rotation and keyboard.
-
Support extensions.
-
Support multiple instances of AlertView/ActionSheet showing one above another.
Requires iOS7 or later. The popping up animation is a spring animation and it's only available on iOS7 and later.
- Showing a plain alert view:
[LGAlertView showAlertWithTitle:@"This is title"
message:@"This is message"
cancelButtonTitle:@"Cancel"
otherButtonTitle:@"OK"
cancelButtonBlock:nil
otherButtonBlock:^(LGAlertView *alertView) {
[alertView dismiss];
}];
Note that to dismiss the AlertView when the "OK" button is clicked, you have to manually call dismiss
. The advantage of this is that you can do something else to the alert like showing wrong message or popping up another AlertView.
- Showing an AlertView with an image on the top:
[LGAlertView showAlertWithTitleImage:[UIImage imageNamed:@"import_done"]
title:@"This is title"
message:@"This is message"
cancelButtonTitle:@"Cancel"
otherButtonTitle:@"OK"
cancelButtonBlock:nil
otherButtonBlock:nil];
- Showing AlertView with a TextField:
[LGAlertView showAlertWithTitle:@"This is Title"
message:@"This is message"
cancelButtonTitle:@"Cancel"
otherButtonTitle:@"OK"
cancelButtonBlock:nil
textFieldBlock:^(LGAlertView *alertView) {
[alertView showErrorMessage:@"Wrong Password" animated:YES];
}];
}
Here you can show some error message if user's input is not valid with optionally a spring animation.
- Showing AlertView with a progress view:
LGAlertView *alertView = [LGAlertView alertWithInProgressImage:[UIImage imageNamed:@"import_in_progress"]
completionImage:[UIImage imageNamed:@"import_done"]
message:@"This is a long long long long long long message"
cancelButtonTitle:@"OK, I know"
otherButtonTitle:@"Please don't"
cancelButtonBlock:nil
otherButtonBlock:nil];
[alertView show];
You can call [alertView animateToCompletionState];
after the progress is completed to transite to completion state, or set alertView.progressView
's animationCompletionCallBack
and in that block call [alertView animateToCompletionState];
so that it will animate to completion state once the progress is completed.
- Showing ActionSheet with 1 options:
[LGActionSheet showActionSheetWithCancelButtonTitle:@"Cancel"
otherButtonTitle:@"OK"
cancelButtonBlock:nil
otherButtonBlock:nil
fromView:nil];
If you pass nil to fromView
, the super view of ActionSheet is the topmost window. But CAUTION: This parameter MUST NOT be nil in extensions as we cannot use UIWindow in extensions.
- Showing ActionSheet with 2 options:
[LGActionSheet showActionSheetWithCancelButtonTitle:@"Cancel"
otherButtonTitle0:@"Option 1"
otherButtonTitle1:@"Option 2"
cancelButtonBlock:nil
otherButtonBlock0:nil
otherButtonBlock1:nil
fromView:nil];
To use LGAlertSheet in extensions, you have to:
-
Define Macro LGAS_APP_EXTENSIONS
-
Either passing a non-nullable superView parameter to init... method (LGActionSheet) or setting superView before showing the AlertView/ActionSheet.