Skip to content

kukumaluCN/JXTAlertController

Repository files navigation

JXTAlertController

CocoaPods compatible  Support  License: MIT

基于UIAlertController的封装,利用链式语法,使得UIAlertController使用起来更简单。

JXTAlertController(>=iOS8)

1.安装

CocoaPods

  • 1.在 Podfile 中添加 pod 'JXTAlertController'。
  • 2.执行 pod install 或 pod update。
  • 3.导入 <JXTAlertController/JXTAlertController.h>。

注意:
如果执行pod search JXTAlertController检索不到,考虑使用pod search JXTAlertController --simple命令,或者尝试更新本地库。

2.示例(更多用法详见demo)

2.1.常规用法

在某一VC内:

[self jxt_showAlertWithTitle:@"title"
                     message:@"message"
           appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
    alertMaker.
    addActionCancelTitle(@"cancel").
    addActionDestructiveTitle(@"按钮1");
} actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) {
    if (buttonIndex == 0) {
        NSLog(@"cancel");
    }
    else if (buttonIndex == 1) {
        NSLog(@"按钮1");
    }
}];

2.2.支持添加textField

[self jxt_showAlertWithTitle:@"title"
                     message:@"message"
           appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
    alertMaker.
    addActionDestructiveTitle(@"获取输入框1").
    addActionDestructiveTitle(@"获取输入框2");
    
    [alertMaker addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"输入框1-请输入";
    }];
    [alertMaker addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"输入框2-请输入";
    }];
} actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) {
    if (buttonIndex == 0) {
        UITextField *textField = alertSelf.textFields.firstObject;
        [self logMsg:textField.text];//不用担心循环引用
    }
    else if (buttonIndex == 1) {
        UITextField *textField = alertSelf.textFields.lastObject;
        [self logMsg:textField.text];
    }
}];

About

基于UIAlertController的封装,利用链式语法,使得UIAlertController使用起来更简单。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published