美文网首页
封装AlertViewController

封装AlertViewController

作者: TimmyR | 来源:发表于2016-10-25 13:33 被阅读51次

    //

    //RYTCustomAlertViewController.h

    //wojiubuxinle

    //

    //Created by timmy on 16/10/9.

    //Copyright © 2016年 timmy. All rights reserved.

    //

    #import

    typedefvoid(^ACTIONBLOCK)(NSString*msg);

    @interfaceRYTCustomAlertViewController :UIAlertController

    + (void)showAlertWithController:(UIViewController*)controller title:(NSString*)title msg:(NSString*)msg;

    + (void)showAlertWithController:(UIViewController*)controller title:(NSString*)title msg:(NSString*)msg style:(UIAlertControllerStyle)style actionFir:(NSString*)actionFir actionSec:(NSString*)actionSec actionThi:(NSString*)actionThi actionFor:(NSString*)actionFor act:(ACTIONBLOCK)act;

    + (void)alertWithController:(UIViewController*)controller seconds:(NSInteger)seconds title:(NSString*)title msg:(NSString*)msg;

    @end

    //

    //RYTCustomAlertViewController.m

    //wojiubuxinle

    //

    //Created by timmy on 16/10/9.

    //Copyright © 2016年 timmy. All rights reserved.

    //

    #import"RYTCustomAlertViewController.h"

    #define SCREEN_WIDTHCGRectGetWidth(self.view.frame)

    #define SCREEN_HEIGHTCGRectGetHeight(self.view.frame)

    @interfaceRYTCustomAlertViewController()

    @end

    @implementationRYTCustomAlertViewController

    - (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

    }

    - (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    }

    + (void)showAlertWithController:(UIViewController*)controller title:(NSString*)title msg:(NSString*)msg {

    UIAlertController*alert = [UIAlertControlleralertControllerWithTitle:titlemessage:msgpreferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction*action = [UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleCancelhandler:nil];

    [alertaddAction:action];

    [controllershowDetailViewController:alertsender:nil];

    }

    + (void)showAlertWithController:(UIViewController*)controller title:(NSString*)title msg:(NSString*)msg style:(UIAlertControllerStyle)style actionFir:(NSString*)actionFir actionSec:(NSString*)actionSec actionThi:(NSString*)actionThi actionFor:(NSString*)actionFor act:(ACTIONBLOCK)act {

    UIAlertController*alert = [UIAlertControlleralertControllerWithTitle:titlemessage:msgpreferredStyle:style];

    if(actionFir) {

    UIAlertAction*action = [UIAlertActionactionWithTitle:actionFirstyle:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

    act(actionFir);

    }];

    [alertaddAction:action];

    }

    if(actionSec) {

    UIAlertAction*action = [UIAlertActionactionWithTitle:actionSecstyle:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

    act(actionSec);

    }];

    [alertaddAction:action];

    }

    if(actionThi) {

    UIAlertAction*action = [UIAlertActionactionWithTitle:actionThistyle:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

    act(actionThi);

    }];

    [alertaddAction:action];

    }

    if(actionFor) {

    UIAlertAction*action = [UIAlertActionactionWithTitle:actionForstyle:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

    act(actionFor);

    }];

    [alertaddAction:action];

    }

    UIAlertAction*cancleAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil];

    [alertaddAction:cancleAction];

    [controllershowDetailViewController:alertsender:nil];

    }

    + (void)alertWithController:(UIViewController*)controller seconds:(NSInteger)seconds title:(NSString*)title msg:(NSString*)msg {

    UIAlertController*alert = [UIAlertControlleralertControllerWithTitle:titlemessage:msgpreferredStyle:UIAlertControllerStyleAlert];

    [controllershowDetailViewController:alertsender:nil];

    NSTimer*timer = [NSTimertimerWithTimeInterval:secondsrepeats:NOblock:^(NSTimer*_Nonnulltimer) {

    [alertdismissViewControllerAnimated:YEScompletion:nil];

    }];

    [[NSRunLoopcurrentRunLoop]addTimer:timerforMode:NSRunLoopCommonModes];

    }

    //NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"heihei"];

    //[hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:50] range:NSMakeRange(0, [[hogan string] length])];

    //[alert setValue:hogan forKey:@"attributedTitle"];

    @end

    相关文章

      网友评论

          本文标题:封装AlertViewController

          本文链接:https://www.haomeiwen.com/subject/gjuruttx.html