UIAlertViewController的简单封装

初识OC,对封装简直一窍不通,只能先从简单的控件开始学起,下面是封装的一个UIAlertViewController分为三种模式:

.h文件

>////  AlertControllerTool.h//  测试篇////  Created by HR on 16/12/13.//  Copyright © 2016年 dawenkeji. All rights reserved.//#import#import@interface AlertControllerTool : NSObject

//没有取消按钮(确认后无跳转)

+ (UIAlertController *)alertMessage:(NSString *)message confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc;

//没有取消按钮(确认后有跳转)

+ (UIAlertController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc;

//有取消按钮

+ (UIViewController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHander:(void(^)(UIAlertAction *))confirmActionHandle cancleHander:(void(^)(UIAlertAction *))cancleActionHandle viewController:(UIViewController *)vc;

@end

.m文件

>//

#import "AlertControllerTool.h"

@implementation AlertControllerTool

//没有取消按钮(确认后无跳转)

+ (UIAlertController *)alertMessage:(NSString *)message confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:

@"温馨提示" message:

message preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:

@"确定"

style:

UIAlertActionStyleDefault

handler:

confirmActionHandle];

[alert addAction:confirmAction];

[vc presentViewController:alert animated:YES completion:nil];

return alert;

}

9528--0001

//没有取消按钮(确认后有跳转)

+ (UIAlertController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:

title message:

message preferredStyle:

*preferredStyle];

UIAlertAction *action = [UIAlertAction actionWithTitle:

@"确定" style:UIAlertActionStyleDefault  handler:confirmActionHandle];

[alert addAction:action];

[vc presentViewController:alert animated:YES completion:nil];

return alert;

}

//有取消按钮

+ (UIViewController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHander:(void(^)(UIAlertAction *))confirmActionHandle cancleHander:(void(^)(UIAlertAction *))cancleActionHandle viewController:(UIViewController *)vc{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:

title message:

message preferredStyle:

*preferredStyle];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:confirmActionHandle];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:cancleActionHandle];

[alert addAction:action1];

[alert addAction:action2];

[vc presentViewController:alert animated:YES completion:nil];

return alert;

}

@end

你可能感兴趣的:(UIAlertViewController的简单封装)