您的位置:首页 > 产品设计 > UI/UE

[x-Code7新功能之二]UIAlertController的练习

2016-04-10 07:55 435 查看
@interface MyPublicFuntions : NSObject
+(void)AlertOkAndCancel:(UIViewController* _Nonnull) AController
Message:(NSString* _Nonnull) AMessgae
OkHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) AOkHandler
CancleHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) ACancelHandler
Completion:(NSInteger (^ _Nullable)()) ACompletion;
+(void)AlertOkOnly:(UIViewController* _Nonnull) AController
Message:(NSString* _Nonnull) AMessgae
OkHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) AOkHandler
Completion:(NSInteger (^ _Nullable)()) ACompletion;
+(void)AlertPassWordOnly:(UIViewController* _Nonnull) AController
OkHandler:(void (^ _Nullable)(UIAlertAction* _Nullable Action
,NSString* _Nullable APassword)) AOkHandler
CancleHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) ACancelHandler
Completion:(NSInteger (^ _Nullable)()) ACompletion;
@end
#import "MyPublicFuntions.h"

@implementation MyPublicFuntions

+(void)AlertOkAndCancel:(UIViewController* _Nonnull) AController
Message:(NSString* _Nonnull) AMessgae
OkHandler:(void (^)(UIAlertAction * _Nullable))AOkHandler
CancleHandler:(void (^)(UIAlertAction * _Nullable))ACancelHandler
Completion:(NSInteger (^)())ACompletion
{
UIAlertController* AlertController = [UIAlertController alertControllerWithTitle:@"询问框" message:AMessgae preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* OkAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(AOkHandler) AOkHandler(action);
}];
UIAlertAction* CancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
if (ACancelHandler) ACancelHandler(action);
}];
[AlertController addAction:OkAction];
[AlertController addAction:CancelAction];
[AController presentViewController:AlertController animated:YES completion:^{
if (ACompletion) ACompletion();
}];
};

+(void)AlertOkOnly:(UIViewController *)AController
Message:(NSString *)AMessgae
OkHandler:(void (^)(UIAlertAction * _Nullable))AOkHandler
Completion:(NSInteger (^)())ACompletion
{
UIAlertController* AlertController = [UIAlertController alertControllerWithTitle:@"提示框" message:AMessgae preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* OkAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(AOkHandler) AOkHandler(action);
}];
[AlertController addAction:OkAction];
[AController presentViewController:AlertController animated:YES completion:^{
if (ACompletion) ACompletion();
}];
}
+(void)AlertPassWordOnly:(UIViewController *)AController OkHandler:(void (^)(UIAlertAction * _Nullable, NSString * _Nullable))AOkHandler CancleHandler:(void (^)(UIAlertAction * _Nullable))ACancelHandler Completion:(NSInteger (^)())ACompletion
{
UIAlertController* AlertController = [UIAlertController alertControllerWithTitle:@"请输入密码" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* OkAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if(AOkHandler) AOkHandler(action,AlertController.textFields.firstObject.text);
}];
UIAlertAction* CancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
if (ACancelHandler) ACancelHandler(action);
}];
[AlertController addAction:OkAction];
[AlertController addAction:CancelAction];
[AlertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"密码";
textField.secureTextEntry = YES;
}];
[AController presentViewController:AlertController animated:YES completion:^{
if (ACompletion) ACompletion();
}];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: