├── .DS_Store ├── .gitignore ├── JXTAlertManager.png ├── JXTAlertManager.podspec ├── JXTAlertManager ├── AlertController │ ├── JXTAlertController.h │ └── JXTAlertController.m ├── AlertView │ ├── JXTAlertView.h │ └── JXTAlertView.m └── JXTAlertManagerHeader.h ├── JXTAlertManagerDemo ├── .DS_Store ├── JXTAlertManagerDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── JXTAlertManagerDemo │ ├── .DS_Store │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── Info.plist │ ├── ShowViewController.h │ ├── ShowViewController.m │ └── main.m ├── LICENSE └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kukumaluCN/JXTAlertManager/acd2cfd7f2894a69670bc27878e293b56436ed72/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /JXTAlertManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kukumaluCN/JXTAlertManager/acd2cfd7f2894a69670bc27878e293b56436ed72/JXTAlertManager.png -------------------------------------------------------------------------------- /JXTAlertManager.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | # 简介 4 | s.name = 'JXTAlertManager' 5 | s.summary = 'A library easy to use UIAlertView and UIAlertViewController on iOS.' 6 | s.authors = { 'kukumaluCN' => '1145049339@qq.com' } 7 | s.social_media_url = 'https://www.jianshu.com/u/c8f8558a4b1d' 8 | 9 | # 版本信息 10 | s.version = '1.0.2' 11 | s.license = { :type => 'MIT', :file => 'LICENSE' } 12 | 13 | # 地址 14 | s.homepage = 'https://github.com/kukumaluCN/JXTAlertManager' 15 | s.source = { :git => 'https://github.com/kukumaluCN/JXTAlertManager.git', :tag => s.version.to_s } 16 | 17 | # 系统 18 | s.requires_arc = true 19 | s.platform = :ios, '8.0' 20 | s.ios.deployment_target = '8.0' 21 | 22 | # 文件 23 | s.source_files = 'JXTAlertManager/**/*.{h,m}' 24 | # s.public_header_files = 'JXTAlertManager/**/*.{h}' 25 | # s.resources = "JXTAlertManager/JXTAlertManager/*.xcassets" 26 | 27 | 28 | # 依赖 29 | # s.libraries = 'sqlite3' 30 | # s.frameworks = 'UIKit', 'CoreFoundation', 'QuartzCore' 31 | # s.dependency "JSONKit", "~> 1.4" 32 | 33 | end 34 | 35 | -------------------------------------------------------------------------------- /JXTAlertManager/AlertController/JXTAlertController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JXTAlertController.h 3 | // JXTAlertManager 4 | // 5 | // Created by JXT on 2016/12/22. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | #pragma mark - I.JXTAlertController构造 15 | 16 | @class JXTAlertController; 17 | /** 18 | JXTAlertController: alertAction配置链 19 | 20 | @param title 标题 21 | @return JXTAlertController对象 22 | */ 23 | typedef JXTAlertController * _Nonnull (^JXTAlertActionTitle)(NSString *title); 24 | 25 | /** 26 | JXTAlertController: alert按钮执行回调 27 | 28 | @param buttonIndex 按钮index(根据添加action的顺序) 29 | @param action UIAlertAction对象 30 | @param alertSelf 本类对象 31 | */ 32 | typedef void (^JXTAlertActionBlock)(NSInteger buttonIndex, UIAlertAction *action, JXTAlertController *alertSelf); 33 | 34 | 35 | /** 36 | JXTAlertController 简介: 37 | 38 | 1.针对系统UIAlertController封装,支持iOS8及以上 39 | 40 | 2.关于iOS9之后的`preferredAction`属性用法: 41 | `alertController.preferredAction = alertController.actions[0];` 42 | 效果为将已存在的某个action字体加粗,原cancel样式的加粗字体成为deafult样式,cancel样式的action仍然排列在最下 43 | 总体意义不大,且仅限于`UIAlertControllerStyleAlert`,actionSheet无效,功能略微鸡肋,不再单独封装 44 | 45 | 3.关于`addTextFieldWithConfigurationHandler:`方法: 46 | 该方法同样仅限于`UIAlertControllerStyleAlert`使用,使用场景较为局限,推荐直接调用,不再针对封装 47 | 48 | 4.关于自定义按钮字体或者颜色,可以利用kvc间接访问这些私有属性,但是不推荐 49 | `[alertAction setValue:[UIColor grayColor] forKey:@"titleTextColor"]` 50 | */ 51 | NS_CLASS_AVAILABLE_IOS(8_0) @interface JXTAlertController : UIAlertController 52 | 53 | 54 | /** 55 | JXTAlertController: 禁用alert弹出动画,默认执行系统的默认弹出动画 56 | */ 57 | - (void)alertAnimateDisabled; 58 | 59 | /** 60 | JXTAlertController: alert弹出后,可配置的回调 61 | */ 62 | @property (nullable, nonatomic, copy) void (^alertDidShown)(void); 63 | 64 | /** 65 | JXTAlertController: alert关闭后,可配置的回调 66 | */ 67 | @property (nullable, nonatomic, copy) void (^alertDidDismiss)(void); 68 | 69 | /** 70 | JXTAlertController: 设置toast模式展示时间:如果alert未添加任何按钮,将会以toast样式展示,这里设置展示时间,默认1s 71 | */ 72 | @property (nonatomic, assign) NSTimeInterval toastStyleDuration; //deafult jxt_alertShowDurationDefault = 1s 73 | 74 | 75 | /** 76 | JXTAlertController: 链式构造alert视图按钮,添加一个alertAction按钮,默认样式,参数为标题 77 | 78 | @return JXTAlertController对象 79 | */ 80 | - (JXTAlertActionTitle)addActionDefaultTitle; 81 | 82 | /** 83 | JXTAlertController: 链式构造alert视图按钮,添加一个alertAction按钮,取消样式,参数为标题(warning:一个alert该样式只能添加一次!!!) 84 | 85 | @return JXTAlertController对象 86 | */ 87 | - (JXTAlertActionTitle)addActionCancelTitle; 88 | 89 | /** 90 | JXTAlertController: 链式构造alert视图按钮,添加一个alertAction按钮,警告样式,参数为标题 91 | 92 | @return JXTAlertController对象 93 | */ 94 | - (JXTAlertActionTitle)addActionDestructiveTitle; 95 | 96 | @end 97 | 98 | 99 | #pragma mark - II.UIViewController扩展使用JXTAlertController 100 | 101 | /** 102 | JXTAlertController: alert构造块 103 | 104 | @param alertMaker JXTAlertController配置对象 105 | */ 106 | typedef void(^JXTAlertAppearanceProcess)(JXTAlertController *alertMaker); 107 | 108 | @interface UIViewController (JXTAlertController) 109 | 110 | /** 111 | JXTAlertController: show-alert(iOS8) 112 | 113 | @param title title 114 | @param message message 115 | @param appearanceProcess alert配置过程 116 | @param actionBlock alert点击响应回调 117 | */ 118 | - (void)jxt_showAlertWithTitle:(nullable NSString *)title 119 | message:(nullable NSString *)message 120 | appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess 121 | actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0); 122 | 123 | /** 124 | JXTAlertController: show-actionSheet(iOS8) 125 | 126 | @param title title 127 | @param message message 128 | @param appearanceProcess actionSheet配置过程 129 | @param actionBlock actionSheet点击响应回调 130 | */ 131 | - (void)jxt_showActionSheetWithTitle:(nullable NSString *)title 132 | message:(nullable NSString *)message 133 | appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess 134 | actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0); 135 | 136 | @end 137 | 138 | NS_ASSUME_NONNULL_END 139 | -------------------------------------------------------------------------------- /JXTAlertManager/AlertController/JXTAlertController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JXTAlertController.m 3 | // JXTAlertManager 4 | // 5 | // Created by JXT on 2016/12/22. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import "JXTAlertController.h" 10 | 11 | //toast默认展示时间 12 | static NSTimeInterval const JXTAlertShowDurationDefault = 1.0f; 13 | 14 | 15 | #pragma mark - I.AlertActionModel 16 | @interface JXTAlertActionModel : NSObject 17 | @property (nonatomic, copy) NSString * title; 18 | @property (nonatomic, assign) UIAlertActionStyle style; 19 | @end 20 | @implementation JXTAlertActionModel 21 | - (instancetype)init 22 | { 23 | if (self = [super init]) { 24 | self.title = @""; 25 | self.style = UIAlertActionStyleDefault; 26 | } 27 | return self; 28 | } 29 | @end 30 | 31 | 32 | 33 | #pragma mark - II.JXTAlertController 34 | /** 35 | AlertActions配置 36 | 37 | @param actionBlock JXTAlertActionBlock 38 | */ 39 | typedef void (^JXTAlertActionsConfig)(JXTAlertActionBlock actionBlock); 40 | 41 | 42 | @interface JXTAlertController () 43 | //JXTAlertActionModel数组 44 | @property (nonatomic, strong) NSMutableArray * jxt_alertActionArray; 45 | //是否操作动画 46 | @property (nonatomic, assign) BOOL jxt_setAlertAnimated; 47 | //action配置 48 | - (JXTAlertActionsConfig)alertActionsConfig; 49 | @end 50 | 51 | @implementation JXTAlertController 52 | 53 | - (void)viewDidLoad { 54 | [super viewDidLoad]; 55 | } 56 | - (void)didReceiveMemoryWarning { 57 | [super didReceiveMemoryWarning]; 58 | } 59 | - (void)viewDidDisappear:(BOOL)animated 60 | { 61 | [super viewDidDisappear:animated]; 62 | if (self.alertDidDismiss) { 63 | self.alertDidDismiss(); 64 | } 65 | } 66 | - (void)dealloc 67 | { 68 | // NSLog(@"test-dealloc"); 69 | } 70 | 71 | #pragma mark - Private 72 | //action-title数组 73 | - (NSMutableArray *)jxt_alertActionArray 74 | { 75 | if (_jxt_alertActionArray == nil) { 76 | _jxt_alertActionArray = [NSMutableArray array]; 77 | } 78 | return _jxt_alertActionArray; 79 | } 80 | //action配置 81 | - (JXTAlertActionsConfig)alertActionsConfig 82 | { 83 | return ^(JXTAlertActionBlock actionBlock) { 84 | if (self.jxt_alertActionArray.count > 0) 85 | { 86 | //创建action 87 | __weak typeof(self)weakSelf = self; 88 | [self.jxt_alertActionArray enumerateObjectsUsingBlock:^(JXTAlertActionModel *actionModel, NSUInteger idx, BOOL * _Nonnull stop) { 89 | UIAlertAction *alertAction = [UIAlertAction actionWithTitle:actionModel.title style:actionModel.style handler:^(UIAlertAction * _Nonnull action) { 90 | __strong typeof(weakSelf)strongSelf = weakSelf; 91 | if (actionBlock) { 92 | actionBlock(idx, action, strongSelf); 93 | } 94 | }]; 95 | //可利用这个改变字体颜色,但是不推荐!!! 96 | // [alertAction setValue:[UIColor grayColor] forKey:@"titleTextColor"]; 97 | //action作为self元素,其block实现如果引用本类指针,会造成循环引用 98 | [self addAction:alertAction]; 99 | }]; 100 | } 101 | else 102 | { 103 | NSTimeInterval duration = self.toastStyleDuration > 0 ? self.toastStyleDuration : JXTAlertShowDurationDefault; 104 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 105 | [self dismissViewControllerAnimated:!(self.jxt_setAlertAnimated) completion:NULL]; 106 | }); 107 | } 108 | }; 109 | } 110 | 111 | #pragma mark - Public 112 | 113 | - (instancetype)initAlertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle 114 | { 115 | if (!(title.length > 0) && (message.length > 0) && (preferredStyle == UIAlertControllerStyleAlert)) { 116 | title = @""; 117 | } 118 | self = [[self class] alertControllerWithTitle:title message:message preferredStyle:preferredStyle]; 119 | if (!self) return nil; 120 | 121 | self.jxt_setAlertAnimated = NO; 122 | self.toastStyleDuration = JXTAlertShowDurationDefault; 123 | 124 | return self; 125 | } 126 | 127 | - (void)alertAnimateDisabled 128 | { 129 | self.jxt_setAlertAnimated = YES; 130 | } 131 | 132 | - (JXTAlertActionTitle)addActionDefaultTitle 133 | { 134 | //该block返回值不是本类属性,只是局部变量,不会造成循环引用 135 | return ^(NSString *title) { 136 | JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init]; 137 | actionModel.title = title; 138 | actionModel.style = UIAlertActionStyleDefault; 139 | [self.jxt_alertActionArray addObject:actionModel]; 140 | return self; 141 | }; 142 | } 143 | 144 | - (JXTAlertActionTitle)addActionCancelTitle 145 | { 146 | return ^(NSString *title) { 147 | JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init]; 148 | actionModel.title = title; 149 | actionModel.style = UIAlertActionStyleCancel; 150 | [self.jxt_alertActionArray addObject:actionModel]; 151 | return self; 152 | }; 153 | } 154 | 155 | - (JXTAlertActionTitle)addActionDestructiveTitle 156 | { 157 | return ^(NSString *title) { 158 | JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init]; 159 | actionModel.title = title; 160 | actionModel.style = UIAlertActionStyleDestructive; 161 | [self.jxt_alertActionArray addObject:actionModel]; 162 | return self; 163 | }; 164 | } 165 | 166 | @end 167 | 168 | 169 | 170 | #pragma mark - III.UIViewController扩展 171 | @implementation UIViewController (JXTAlertController) 172 | 173 | - (void)jxt_showAlertWithPreferredStyle:(UIAlertControllerStyle)preferredStyle title:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock 174 | { 175 | if (appearanceProcess) 176 | { 177 | JXTAlertController *alertMaker = [[JXTAlertController alloc] initAlertControllerWithTitle:title message:message preferredStyle:preferredStyle]; 178 | //防止nil 179 | if (!alertMaker) { 180 | return ; 181 | } 182 | //加工链 183 | appearanceProcess(alertMaker); 184 | //配置响应 185 | alertMaker.alertActionsConfig(actionBlock); 186 | // alertMaker.alertActionsConfig(^(NSInteger buttonIndex, UIAlertAction *action){ 187 | // if (actionBlock) { 188 | // actionBlock(buttonIndex, action); 189 | // } 190 | // }); 191 | 192 | if (alertMaker.alertDidShown) 193 | { 194 | [self presentViewController:alertMaker animated:!(alertMaker.jxt_setAlertAnimated) completion:^{ 195 | alertMaker.alertDidShown(); 196 | }]; 197 | } 198 | else 199 | { 200 | [self presentViewController:alertMaker animated:!(alertMaker.jxt_setAlertAnimated) completion:NULL]; 201 | } 202 | } 203 | } 204 | 205 | - (void)jxt_showAlertWithTitle:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock 206 | { 207 | [self jxt_showAlertWithPreferredStyle:UIAlertControllerStyleAlert title:title message:message appearanceProcess:appearanceProcess actionsBlock:actionBlock]; 208 | } 209 | 210 | - (void)jxt_showActionSheetWithTitle:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock 211 | { 212 | [self jxt_showAlertWithPreferredStyle:UIAlertControllerStyleActionSheet title:title message:message appearanceProcess:appearanceProcess actionsBlock:actionBlock]; 213 | } 214 | 215 | @end 216 | 217 | -------------------------------------------------------------------------------- /JXTAlertManager/AlertView/JXTAlertView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JXTAlertView.h 3 | // JXTAlertManager 4 | // 5 | // Created by JXT on 2016/12/20. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define jxt_dispatch_main_async_safe(block)\ 12 | if ([NSThread isMainThread]) {\ 13 | block();\ 14 | } else {\ 15 | dispatch_async(dispatch_get_main_queue(), block);\ 16 | } 17 | /** 18 | 回调主线程(显示alert必须在主线程执行) 19 | 20 | @param block 执行块 21 | */ 22 | static inline void jxt_getSafeMainQueue(_Nonnull dispatch_block_t block) 23 | { 24 | jxt_dispatch_main_async_safe(block); 25 | } 26 | 27 | /** 28 | alert按钮执行回调 29 | 30 | @param buttonIndex 按钮index 31 | */ 32 | typedef void (^JXTAlertClickBlock)(NSInteger buttonIndex); 33 | 34 | 35 | // MARK: 1.常规的alert 36 | /** 37 | * JXTAlertView: 两个按钮alert 38 | */ 39 | void jxt_showAlertTwoButton(NSString * _Nullable title, 40 | NSString * _Nullable message, 41 | NSString * _Nullable cancelButtonTitle, 42 | JXTAlertClickBlock _Nullable cancelBlock, 43 | NSString * _Nullable otherButtonTitle, 44 | JXTAlertClickBlock _Nullable otherBlock); 45 | /** 46 | * JXTAlertView: 一个按钮alert 47 | */ 48 | void jxt_showAlertOneButton(NSString * _Nullable title, 49 | NSString * _Nullable message, 50 | NSString * _Nullable cancelButtonTitle, 51 | JXTAlertClickBlock _Nullable cancelBlock); 52 | /** 53 | * JXTAlertView: 一个固定按钮alert 54 | */ 55 | void jxt_showAlertTitle(NSString * _Nullable title); 56 | /** 57 | * JXTAlertView: 一个固定按钮alert 58 | */ 59 | void jxt_showAlertMessage(NSString * _Nullable message); 60 | /** 61 | * JXTAlertView: 一个固定按钮alert 62 | */ 63 | void jxt_showAlertTitleMessage(NSString * _Nullable title, 64 | NSString * _Nullable message); 65 | 66 | 67 | // MARK: 2.无按钮toast 68 | /** 69 | * JXTAlertView: 无按钮toast,支持自定义关闭回调 70 | */ 71 | void jxt_showToastTitleMessageDismiss(NSString * _Nullable title, 72 | NSString * _Nullable message, 73 | NSTimeInterval duration, 74 | JXTAlertClickBlock _Nullable dismissCompletion); 75 | /** 76 | * JXTAlertView: 无按钮toast,支持自定义关闭回调 77 | */ 78 | void jxt_showToastTitleDismiss(NSString * _Nullable title, 79 | NSTimeInterval duration, 80 | JXTAlertClickBlock _Nullable dismissCompletion); 81 | /** 82 | * JXTAlertView: 无按钮toast,支持自定义关闭回调 83 | */ 84 | void jxt_showToastMessageDismiss(NSString * _Nullable message, 85 | NSTimeInterval duration, 86 | JXTAlertClickBlock _Nullable dismissCompletion); 87 | /** 88 | * JXTAlertView: 无按钮toast 89 | */ 90 | void jxt_showToastTitle(NSString * _Nullable title, 91 | NSTimeInterval duration); 92 | /** 93 | * JXTAlertView: 无按钮toast 94 | */ 95 | void jxt_showToastMessage(NSString * _Nullable message, 96 | NSTimeInterval duration); 97 | 98 | 99 | // MARK: 3.文字HUD,代码执行关闭 100 | /** 101 | * JXTAlertView: 文字HUD,jxt_dismissHUD()执行关闭 102 | */ 103 | void jxt_showTextHUDTitleMessage(NSString * _Nullable title, 104 | NSString * _Nullable message); 105 | /** 106 | * JXTAlertView: 文字HUD,jxt_dismissHUD()执行关闭 107 | */ 108 | void jxt_showTextHUDTitle(NSString * _Nullable title); 109 | /** 110 | * JXTAlertView: 文字HUD,jxt_dismissHUD()执行关闭 111 | */ 112 | void jxt_showTextHUDMessage(NSString * _Nullable message); 113 | 114 | 115 | // MARK: 4.loadHUD,代码执行关闭 116 | /** 117 | * JXTAlertView: loadHUD,jxt_dismissHUD()执行关闭 118 | */ 119 | void jxt_showLoadingHUDTitleMessage(NSString * _Nullable title, 120 | NSString * _Nullable message); 121 | /** 122 | * JXTAlertView: loadHUD,jxt_dismissHUD()执行关闭 123 | */ 124 | void jxt_showLoadingHUDTitle(NSString * _Nullable title); 125 | /** 126 | * JXTAlertView: loadHUD,jxt_dismissHUD()执行关闭 127 | */ 128 | void jxt_showLoadingHUDMessage(NSString * _Nullable message); 129 | 130 | 131 | // MARK: 5.ProgressHUD,代码执行关闭 132 | /** 133 | * JXTAlertView: ProgressHUD,jxt_dismissHUD()执行关闭 134 | */ 135 | void jxt_showProgressHUDTitleMessage(NSString * _Nullable title, 136 | NSString * _Nullable message); 137 | /** 138 | * JXTAlertView: ProgressHUD,jxt_dismissHUD()执行关闭 139 | */ 140 | void jxt_showProgressHUDTitle(NSString * _Nullable title); 141 | /** 142 | * JXTAlertView: ProgressHUD,jxt_dismissHUD()执行关闭 143 | */ 144 | void jxt_showProgressHUDMessage(NSString * _Nullable message); 145 | /** 146 | * JXTAlertView: ProgressHUD,设置进度值 147 | */ 148 | void jxt_setHUDProgress(float progress); 149 | 150 | 151 | // MARK: 6.HUD公用 152 | /** 153 | * JXTAlertView: 设置HUD成功状态 154 | */ 155 | void jxt_setHUDSuccessTitleMessage(NSString * _Nullable title, 156 | NSString * _Nullable message); 157 | /** 158 | * JXTAlertView: 设置HUD成功状态 159 | */ 160 | void jxt_setHUDSuccessTitle(NSString * _Nullable title); 161 | /** 162 | * JXTAlertView: 设置HUD成功状态 163 | */ 164 | void jxt_setHUDSuccessMessage(NSString * _Nullable message); 165 | 166 | /** 167 | * JXTAlertView: 设置HUD失败状态 168 | */ 169 | void jxt_setHUDFailTitleMessage(NSString * _Nullable title, 170 | NSString * _Nullable message); 171 | /** 172 | * JXTAlertView: 设置HUD失败状态 173 | */ 174 | void jxt_setHUDFailTitle(NSString * _Nullable title); 175 | /** 176 | * JXTAlertView: 设置HUD失败状态 177 | */ 178 | void jxt_setHUDFailMessage(NSString * _Nullable message); 179 | 180 | /** 181 | * JXTAlertView: 关闭HUD 182 | */ 183 | void jxt_dismissHUD(void); 184 | 185 | 186 | 187 | /** 188 | JXTAlertView 简介: 189 | 190 | 开发调试使用简易alert/HUD工具 191 | 192 | 部分提供C函数方便使用,所有show方法的C函数均默认回调主线程 193 | */ 194 | @interface JXTAlertView : UIAlertView 195 | 196 | /** 197 | JXTAlertView: 最多支持两个按钮的alert 198 | 199 | @param title title 200 | @param message message 201 | @param cancelButtonTitle 取消按钮标题 202 | @param otherButtonTitle 其他按钮标题 203 | @param cancelBlock 取消按钮回调 204 | @param otherBlock 其他按钮回调 205 | */ 206 | + (void)showAlertViewWithTitle:(nullable NSString *)title 207 | message:(nullable NSString *)message 208 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle 209 | otherButtonTitle:(nullable NSString *)otherButtonTitle 210 | cancelButtonBlock:(nullable JXTAlertClickBlock)cancelBlock 211 | otherButtonBlock:(nullable JXTAlertClickBlock)otherBlock; 212 | 213 | 214 | /** 215 | JXTAlertView: 不定数量按钮alert 216 | 217 | @param title title 218 | @param message message 219 | @param cancelButtonTitle 取消按钮标题 220 | @param buttonIndexBlock 按钮回调 221 | @param otherButtonTitles 其他按钮标题列表 222 | */ 223 | + (void)showAlertViewWithTitle:(nullable NSString *)title 224 | message:(nullable NSString *)message 225 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle 226 | buttonIndexBlock:(nullable JXTAlertClickBlock)buttonIndexBlock 227 | otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; 228 | 229 | 230 | /** 231 | JXTAlertView: 不带按钮自动消失的toast 232 | 233 | @param title title 234 | @param message message 235 | @param duration 显示时间 236 | @param dismissCompletion 关闭后回调 237 | */ 238 | + (void)showToastViewWithTitle:(nullable NSString *)title 239 | message:(nullable NSString *)message 240 | duration:(NSTimeInterval)duration 241 | dismissCompletion:(nullable JXTAlertClickBlock)dismissCompletion; 242 | 243 | 244 | /** 245 | JXTAlertView: 文字HUD 246 | 247 | @param title title 248 | @param message message 249 | */ 250 | + (void)showTextHUDWithTitle:(nullable NSString *)title 251 | message:(nullable NSString *)message; 252 | 253 | 254 | /** 255 | JXTAlertView: loadHUD 256 | 257 | @param title title 258 | @param message message 259 | */ 260 | + (void)showLoadingHUDWithTitle:(nullable NSString *)title 261 | message:(nullable NSString *)message; 262 | 263 | 264 | /** 265 | JXTAlertView: progressHUD 266 | 267 | @param title title 268 | @param message message 269 | */ 270 | + (void)showProgressHUDWithTitle:(nullable NSString *)title 271 | message:(nullable NSString *)message; 272 | /** 273 | JXTAlertView: progressHUD,进度条进度值 274 | 275 | @param progress 进度值 276 | */ 277 | + (void)setHUDProgress:(float)progress; 278 | 279 | 280 | /** 281 | JXTAlertView: HUD公用方法,设置成功状态 282 | 283 | @param title title 284 | @param message message 285 | */ 286 | + (void)setHUDSuccessStateWithTitle:(nullable NSString *)title 287 | message:(nullable NSString *)message; 288 | /** 289 | JXTAlertView: HUD公用方法,设置失败状态 290 | 291 | @param title title 292 | @param message message 293 | */ 294 | + (void)setHUDFailStateWithTitle:(nullable NSString *)title 295 | message:(nullable NSString *)message; 296 | /** 297 | JXTAlertView: HUD公用方法,关闭HUD 298 | */ 299 | + (void)dismissHUD; 300 | 301 | @end 302 | -------------------------------------------------------------------------------- /JXTAlertManager/AlertView/JXTAlertView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JXTAlertView.m 3 | // JXTAlertManager 4 | // 5 | // Created by JXT on 2016/12/20. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import "JXTAlertView.h" 10 | 11 | #pragma mark - Private 12 | /** 13 | * 取消按钮默认标题 14 | */ 15 | static NSString *const JXTCancelButtonTitleDefault = @"确定"; 16 | /** 17 | * toast默认展示时间,当设置为0时,用该值 18 | */ 19 | static NSTimeInterval const JXTToastShowDurationDefault = 1.0f; 20 | /** 21 | * alertView子视图key 22 | */ 23 | static NSString *const JXTAlertViewAccessoryViewKey = @"accessoryView"; 24 | 25 | 26 | #pragma mark - Public 27 | //1.常规alert 28 | void jxt_showAlertTwoButton(NSString *title, NSString *message, NSString *cancelButtonTitle, JXTAlertClickBlock cancelBlock, NSString *otherButtonTitle, JXTAlertClickBlock otherBlock) 29 | { 30 | jxt_getSafeMainQueue(^{ 31 | [JXTAlertView showAlertViewWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitle:otherButtonTitle cancelButtonBlock:cancelBlock otherButtonBlock:otherBlock]; 32 | }); 33 | } 34 | void jxt_showAlertOneButton(NSString *title, NSString *message, NSString *cancelButtonTitle, JXTAlertClickBlock cancelBlock) 35 | { 36 | jxt_showAlertTwoButton(title, message, cancelButtonTitle, cancelBlock, nil, NULL); 37 | } 38 | void jxt_showAlertTitle(NSString *title) 39 | { 40 | jxt_showAlertTwoButton(title, nil, JXTCancelButtonTitleDefault, NULL, nil, NULL); 41 | } 42 | void jxt_showAlertMessage(NSString *message) 43 | { 44 | jxt_showAlertTwoButton(@"", message, JXTCancelButtonTitleDefault, NULL, nil, NULL); 45 | } 46 | void jxt_showAlertTitleMessage(NSString *title, NSString *message) 47 | { 48 | jxt_showAlertTwoButton(title, message, JXTCancelButtonTitleDefault, NULL, nil, NULL); 49 | } 50 | 51 | //2.无按钮toast 52 | void jxt_showToastTitleMessageDismiss(NSString *title, NSString *message, NSTimeInterval duration, JXTAlertClickBlock dismissCompletion) 53 | { 54 | jxt_getSafeMainQueue(^{ 55 | [JXTAlertView showToastViewWithTitle:title message:message duration:duration dismissCompletion:dismissCompletion]; 56 | }); 57 | } 58 | void jxt_showToastTitleDismiss(NSString *title, NSTimeInterval duration, JXTAlertClickBlock dismissCompletion) 59 | { 60 | jxt_showToastTitleMessageDismiss(title, nil, duration, dismissCompletion); 61 | } 62 | void jxt_showToastMessageDismiss(NSString *message, NSTimeInterval duration, JXTAlertClickBlock dismissCompletion) 63 | { 64 | jxt_showToastTitleMessageDismiss(@"", message, duration, dismissCompletion); 65 | } 66 | void jxt_showToastTitle(NSString *title, NSTimeInterval duration) 67 | { 68 | jxt_showToastTitleMessageDismiss(title, nil, duration, NULL); 69 | } 70 | void jxt_showToastMessage(NSString *message, NSTimeInterval duration) 71 | { 72 | jxt_showToastTitleMessageDismiss(@"", message, duration, NULL); 73 | } 74 | 75 | //3.文字HUD 76 | void jxt_showTextHUDTitleMessage(NSString *title, NSString *message) 77 | { 78 | jxt_getSafeMainQueue(^{ 79 | [JXTAlertView showTextHUDWithTitle:title message:message]; 80 | }); 81 | } 82 | void jxt_showTextHUDTitle(NSString *title) 83 | { 84 | jxt_showTextHUDTitleMessage(title, nil); 85 | } 86 | void jxt_showTextHUDMessage(NSString *message) 87 | { 88 | jxt_showTextHUDTitleMessage(@"", message); 89 | } 90 | 91 | //4.loadHUD 92 | void jxt_showLoadingHUDTitleMessage(NSString *title, NSString *message) 93 | { 94 | jxt_getSafeMainQueue(^{ 95 | [JXTAlertView showLoadingHUDWithTitle:title message:message]; 96 | }); 97 | } 98 | void jxt_showLoadingHUDTitle(NSString *title) 99 | { 100 | jxt_showLoadingHUDTitleMessage(title, nil); 101 | } 102 | void jxt_showLoadingHUDMessage(NSString *message) 103 | { 104 | jxt_showLoadingHUDTitleMessage(@"", message); 105 | } 106 | 107 | //5.progressHUD 108 | void jxt_showProgressHUDTitleMessage(NSString *title, NSString *message) 109 | { 110 | jxt_getSafeMainQueue(^{ 111 | [JXTAlertView showProgressHUDWithTitle:title message:message]; 112 | }); 113 | } 114 | void jxt_showProgressHUDTitle(NSString *title) 115 | { 116 | jxt_showProgressHUDTitleMessage(title, nil); 117 | } 118 | void jxt_showProgressHUDMessage(NSString *message) 119 | { 120 | jxt_showProgressHUDTitleMessage(@"", message); 121 | } 122 | void jxt_setHUDProgress(float progress) 123 | { 124 | [JXTAlertView setHUDProgress:progress]; 125 | } 126 | 127 | //6.HUD公用 128 | //成功状态 129 | void jxt_setHUDSuccessTitleMessage(NSString *title, NSString *message) 130 | { 131 | jxt_getSafeMainQueue(^{ 132 | [JXTAlertView setHUDSuccessStateWithTitle:title message:message]; 133 | }); 134 | } 135 | void jxt_setHUDSuccessTitle(NSString *title) 136 | { 137 | jxt_setHUDSuccessTitleMessage(title, nil); 138 | } 139 | void jxt_setHUDSuccessMessage(NSString *message) 140 | { 141 | jxt_setHUDSuccessTitleMessage(@"", message); 142 | } 143 | //失败状态 144 | void jxt_setHUDFailTitleMessage(NSString *title, NSString *message) 145 | { 146 | jxt_getSafeMainQueue(^{ 147 | [JXTAlertView setHUDFailStateWithTitle:title message:message]; 148 | }); 149 | } 150 | void jxt_setHUDFailTitle(NSString *title) 151 | { 152 | jxt_setHUDFailTitleMessage(title, nil); 153 | } 154 | void jxt_setHUDFailMessage(NSString *message) 155 | { 156 | jxt_setHUDFailTitleMessage(@"", message); 157 | } 158 | //关闭HUD 159 | void jxt_dismissHUD(void) 160 | { 161 | jxt_getSafeMainQueue(^{ 162 | [JXTAlertView dismissHUD]; 163 | }); 164 | } 165 | 166 | 167 | #pragma mark - define 168 | /** 169 | * JXTAlertType 170 | */ 171 | typedef NS_ENUM(NSInteger, JXTAlertType) { 172 | JXTAlertTypeNormal, 173 | JXTAlertTypeToast, 174 | JXTAlertTypeHUD 175 | }; 176 | 177 | /** 178 | * JXTAlertHUDType 179 | */ 180 | typedef NS_ENUM(NSInteger, JXTAlertHUDType) { 181 | JXTAlertHUDTypeTextOnly, 182 | JXTAlertHUDTypeLoading, 183 | JXTAlertHUDTypeProgress 184 | }; 185 | 186 | 187 | @interface JXTAlertView () 188 | //block 189 | @property (nonatomic, copy) JXTAlertClickBlock buttonClickBlock; 190 | @property (nonatomic, copy) JXTAlertClickBlock completionBlock; 191 | //type 192 | @property (nonatomic, assign) JXTAlertType alertType; 193 | @property (nonatomic, assign) JXTAlertHUDType alertHUDType; 194 | //HUD附件 195 | @property (nonatomic, strong) UIActivityIndicatorView *indicatorView; 196 | @property (nonatomic, strong) UIProgressView *progressView; 197 | 198 | - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle, ... NS_REQUIRES_NIL_TERMINATION; 199 | 200 | @end 201 | 202 | @implementation JXTAlertView 203 | 204 | #pragma mark - Init 205 | - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle, ... 206 | { 207 | self = [self initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitle, nil]; 208 | if (!self) return nil; 209 | 210 | return self; 211 | } 212 | 213 | #pragma mark - shared 214 | static JXTAlertView *__jxt_commonHUD = nil; 215 | + (instancetype)sharedCommonHUDWithHUDType:(JXTAlertHUDType)HUDType 216 | { 217 | if (__jxt_commonHUD == nil) 218 | { 219 | __jxt_commonHUD = [[JXTAlertView alloc] initWithTitle:nil message:nil cancelButtonTitle:nil otherButtonTitle:nil]; 220 | // 221 | __jxt_commonHUD.alertType = JXTAlertTypeHUD; 222 | __jxt_commonHUD.alertHUDType = HUDType; 223 | 224 | switch (HUDType) 225 | { 226 | case JXTAlertHUDTypeTextOnly: 227 | break; 228 | case JXTAlertHUDTypeLoading: 229 | { 230 | //添加指示器 231 | UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 232 | indicatorView.color = [UIColor blackColor]; 233 | [indicatorView startAnimating]; 234 | __jxt_commonHUD.indicatorView = indicatorView; 235 | //强制添加子视图 236 | if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) 237 | { 238 | [__jxt_commonHUD setValue:indicatorView forKey:JXTAlertViewAccessoryViewKey]; 239 | } 240 | else 241 | { 242 | [__jxt_commonHUD addSubview:indicatorView]; 243 | } 244 | break; 245 | } 246 | case JXTAlertHUDTypeProgress: 247 | { 248 | //添加进度条 249 | UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; 250 | progressView.progressTintColor = [UIColor blackColor]; 251 | progressView.progress = 0.0; 252 | __jxt_commonHUD.progressView = progressView; 253 | //强制添加子视图 254 | if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) 255 | { 256 | [__jxt_commonHUD setValue:progressView forKey:JXTAlertViewAccessoryViewKey]; 257 | } 258 | else 259 | { 260 | [__jxt_commonHUD addSubview:progressView]; 261 | } 262 | break; 263 | } 264 | } 265 | } 266 | return __jxt_commonHUD; 267 | } 268 | + (JXTAlertView *)sharedCommonHUD 269 | { 270 | return __jxt_commonHUD; 271 | } 272 | + (void)clearCommonHUD 273 | { 274 | __jxt_commonHUD = nil; 275 | } 276 | 277 | //重写setValue:forUndefinedKey:方法,处理不存在的key赋值,防止崩溃 278 | - (void)setValue:(id)value forUndefinedKey:(NSString *)key 279 | { 280 | NSLog(@"key: %@ 不存在", key); 281 | } 282 | - (id)valueForUndefinedKey:(NSString *)key 283 | { 284 | NSLog(@"value: %@ 不存在", key); 285 | return nil; 286 | } 287 | 288 | 289 | #pragma mark - Methods 290 | //1.常规alert 291 | + (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle cancelButtonBlock:(JXTAlertClickBlock)cancelBlock otherButtonBlock:(JXTAlertClickBlock)otherBlock 292 | { 293 | if (!(title.length > 0) && message.length > 0) { 294 | title = @""; 295 | } 296 | JXTAlertView *alertView = [[JXTAlertView alloc] initWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitle:otherButtonTitle, nil]; 297 | 298 | alertView.alertType = JXTAlertTypeNormal; 299 | 300 | alertView.buttonClickBlock = ^(NSInteger buttonIndex){ 301 | if (buttonIndex == 0) 302 | { 303 | if (cancelBlock) { 304 | cancelBlock(buttonIndex); 305 | } 306 | } 307 | else if (buttonIndex == 1) 308 | { 309 | if (otherBlock) { 310 | otherBlock(buttonIndex); 311 | } 312 | } 313 | }; 314 | 315 | [alertView show]; 316 | } 317 | //不定按钮 318 | + (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle buttonIndexBlock:(JXTAlertClickBlock)buttonIndexBlock otherButtonTitles:(NSString *)otherButtonTitles, ... 319 | { 320 | if (!(title.length > 0) && message.length > 0) { 321 | title = @""; 322 | } 323 | JXTAlertView *alertView = [[JXTAlertView alloc] initWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitle:nil]; 324 | 325 | alertView.alertType = JXTAlertTypeNormal; 326 | alertView.buttonClickBlock = buttonIndexBlock; 327 | 328 | if (otherButtonTitles) 329 | { 330 | va_list args;//定义一个指向个数可变的参数列表指针 331 | va_start(args, otherButtonTitles);//得到第一个可变参数地址 332 | for (NSString *arg = otherButtonTitles; arg != nil; arg = va_arg(args, NSString *)) 333 | { 334 | [alertView addButtonWithTitle:arg]; 335 | } 336 | va_end(args);//置空指针 337 | } 338 | 339 | [alertView show]; 340 | } 341 | 342 | //2.无按钮toast 343 | + (void)showToastViewWithTitle:(NSString *)title message:(NSString *)message duration:(NSTimeInterval)duration dismissCompletion:(JXTAlertClickBlock)dismissCompletion 344 | { 345 | if (!(title.length > 0) && message.length > 0) { 346 | title = @""; 347 | } 348 | JXTAlertView *toastView = [[JXTAlertView alloc] initWithTitle:title message:message cancelButtonTitle:nil otherButtonTitle:nil]; 349 | 350 | toastView.alertType = JXTAlertTypeToast; 351 | 352 | toastView.completionBlock = ^(NSInteger buttonIndex){ 353 | if (buttonIndex == 0) 354 | { 355 | if (dismissCompletion) { 356 | dismissCompletion(buttonIndex); 357 | } 358 | } 359 | }; 360 | 361 | [toastView show]; 362 | 363 | duration = duration > 0 ? duration : JXTToastShowDurationDefault; 364 | [toastView performSelector:@selector(dismissToastView:) withObject:toastView afterDelay:duration]; 365 | } 366 | 367 | - (void)dismissToastView:(UIAlertView *)toastView 368 | { 369 | [toastView dismissWithClickedButtonIndex:0 animated:YES]; 370 | } 371 | 372 | //3.文字HUD 373 | + (void)showTextHUDWithTitle:(NSString *)title message:(NSString *)message 374 | { 375 | if (!(title.length > 0) && message.length > 0) { 376 | title = @""; 377 | } 378 | JXTAlertView *textHUD = [JXTAlertView sharedCommonHUDWithHUDType:JXTAlertHUDTypeTextOnly]; 379 | 380 | textHUD.title = title; 381 | textHUD.message = message; 382 | // textHUD.delegate = nil; 383 | 384 | [textHUD show]; 385 | } 386 | 387 | //4.loadHUD 388 | + (void)showLoadingHUDWithTitle:(NSString *)title message:(NSString *)message 389 | { 390 | if (!(title.length > 0) && message.length > 0) { 391 | title = @""; 392 | } 393 | JXTAlertView *loadingHUD = [JXTAlertView sharedCommonHUDWithHUDType:JXTAlertHUDTypeLoading]; 394 | 395 | loadingHUD.title = title; 396 | loadingHUD.message = message; 397 | 398 | [loadingHUD show]; 399 | } 400 | 401 | //5.progressHUD 402 | + (void)showProgressHUDWithTitle:(NSString *)title message:(NSString *)message 403 | { 404 | if (!(title.length > 0) && message.length > 0) { 405 | title = @""; 406 | } 407 | JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUDWithHUDType:JXTAlertHUDTypeProgress]; 408 | 409 | alertHUD.title = title; 410 | alertHUD.message = message; 411 | 412 | [alertHUD show]; 413 | } 414 | + (void)setHUDProgress:(float)progress 415 | { 416 | JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD]; 417 | [alertHUD.progressView setProgress:progress animated:YES]; 418 | 419 | if (progress >= 1.0) { 420 | [alertHUD.progressView setProgress:1]; 421 | // [alertHUD dismissWithClickedButtonIndex:0 animated:YES]; 422 | } 423 | } 424 | 425 | //6.HUD公用 426 | + (void)setHUDSuccessStateWithTitle:(NSString *)title message:(NSString *)message 427 | { 428 | JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD]; 429 | alertHUD.title = title; 430 | alertHUD.message = message; 431 | 432 | switch (alertHUD.alertHUDType) 433 | { 434 | case JXTAlertHUDTypeTextOnly: 435 | break; 436 | case JXTAlertHUDTypeLoading: 437 | { 438 | [alertHUD.indicatorView stopAnimating]; 439 | if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) 440 | { 441 | [alertHUD setValue:nil forKey:JXTAlertViewAccessoryViewKey]; 442 | } 443 | else 444 | { 445 | [alertHUD.indicatorView removeFromSuperview]; 446 | } 447 | alertHUD.indicatorView = nil; 448 | break; 449 | } 450 | case JXTAlertHUDTypeProgress: 451 | { 452 | [alertHUD.progressView setProgress:1 animated:YES]; 453 | break; 454 | } 455 | } 456 | } 457 | + (void)setHUDFailStateWithTitle:(NSString *)title message:(NSString *)message 458 | { 459 | JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD]; 460 | alertHUD.title = title; 461 | alertHUD.message = message; 462 | 463 | switch (alertHUD.alertHUDType) 464 | { 465 | case JXTAlertHUDTypeTextOnly: 466 | break; 467 | case JXTAlertHUDTypeLoading: 468 | { 469 | [alertHUD.indicatorView stopAnimating]; 470 | if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) 471 | { 472 | [alertHUD setValue:nil forKey:JXTAlertViewAccessoryViewKey]; 473 | } 474 | else 475 | { 476 | [alertHUD.indicatorView removeFromSuperview]; 477 | } 478 | alertHUD.indicatorView = nil; 479 | break; 480 | } 481 | case JXTAlertHUDTypeProgress: 482 | { 483 | [alertHUD.progressView setProgress:0 animated:YES]; 484 | break; 485 | } 486 | } 487 | } 488 | + (void)dismissHUD 489 | { 490 | JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD]; 491 | switch (alertHUD.alertHUDType) 492 | { 493 | case JXTAlertHUDTypeTextOnly: 494 | break; 495 | case JXTAlertHUDTypeLoading: 496 | { 497 | [alertHUD.indicatorView stopAnimating]; 498 | alertHUD.indicatorView = nil; 499 | break; 500 | } 501 | case JXTAlertHUDTypeProgress: 502 | break; 503 | } 504 | [alertHUD dismissWithClickedButtonIndex:0 animated:YES]; 505 | } 506 | 507 | 508 | #pragma mark - Delegate 509 | - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 510 | { 511 | if (self.buttonClickBlock) { 512 | self.buttonClickBlock(buttonIndex); 513 | } 514 | self.buttonClickBlock = NULL;//解除闭环 515 | } 516 | 517 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 518 | { 519 | if (self.completionBlock) { 520 | self.completionBlock(buttonIndex); 521 | } 522 | self.completionBlock = NULL;//解除闭环 523 | 524 | switch (self.alertType) 525 | { 526 | case JXTAlertTypeNormal: 527 | break; 528 | 529 | case JXTAlertTypeToast: 530 | { 531 | //清理performSelector,防止意外情况下的内存泄漏 532 | [NSObject cancelPreviousPerformRequestsWithTarget:alertView selector:@selector(dismissToastView:) object:alertView]; 533 | break; 534 | } 535 | case JXTAlertTypeHUD: 536 | { 537 | //清理static 538 | [JXTAlertView clearCommonHUD]; 539 | break; 540 | } 541 | } 542 | } 543 | 544 | @end 545 | -------------------------------------------------------------------------------- /JXTAlertManager/JXTAlertManagerHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // JXTAlertManagerHeader.h 3 | // JXTAlertManagerDemo 4 | // 5 | // Created by JXT on 2016/12/22. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #ifndef JXTAlertManagerHeader_h 10 | #define JXTAlertManagerHeader_h 11 | 12 | #import "JXTAlertView.h" 13 | 14 | //以下适配,只做提示用,实际使用,如果要适配iOS7,对应方法还是需要自行适配 15 | //不然的话,可能因为这个宏,导致bug,因为新版xcode编译,对应方法是可以使用的(因为xcode的API存在),但是实际在对应系统上,可能就崩溃了 16 | #ifdef NSFoundationVersionNumber_iOS_8_0 17 | #import "JXTAlertController.h" 18 | #endif 19 | 20 | #endif /* JXTAlertManagerHeader_h */ 21 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kukumaluCN/JXTAlertManager/acd2cfd7f2894a69670bc27878e293b56436ed72/JXTAlertManagerDemo/.DS_Store -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A768DF8A1E0A6388005659B5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A768DF891E0A6388005659B5 /* main.m */; }; 11 | A768DF8D1E0A6388005659B5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A768DF8C1E0A6388005659B5 /* AppDelegate.m */; }; 12 | A768DF951E0A6388005659B5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A768DF941E0A6388005659B5 /* Assets.xcassets */; }; 13 | A768DF981E0A6388005659B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A768DF961E0A6388005659B5 /* LaunchScreen.storyboard */; }; 14 | A768DFA11E0A63BE005659B5 /* ShowViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A768DFA01E0A63BE005659B5 /* ShowViewController.m */; }; 15 | A7AE30A820DB98DD006C690F /* JXTAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = A7AE30A220DB98DD006C690F /* JXTAlertController.m */; }; 16 | A7AE30A920DB98DD006C690F /* JXTAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = A7AE30A720DB98DD006C690F /* JXTAlertView.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | A768DF851E0A6388005659B5 /* JXTAlertManagerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JXTAlertManagerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | A768DF891E0A6388005659B5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | A768DF8B1E0A6388005659B5 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | A768DF8C1E0A6388005659B5 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | A768DF941E0A6388005659B5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | A768DF971E0A6388005659B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | A768DF991E0A6388005659B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | A768DF9F1E0A63BE005659B5 /* ShowViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShowViewController.h; sourceTree = ""; }; 28 | A768DFA01E0A63BE005659B5 /* ShowViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowViewController.m; sourceTree = ""; }; 29 | A7AE30A120DB98DD006C690F /* JXTAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertController.h; sourceTree = ""; }; 30 | A7AE30A220DB98DD006C690F /* JXTAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JXTAlertController.m; sourceTree = ""; }; 31 | A7AE30A320DB98DD006C690F /* JXTAlertManagerHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertManagerHeader.h; sourceTree = ""; }; 32 | A7AE30A520DB98DD006C690F /* JXTAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertView.h; sourceTree = ""; }; 33 | A7AE30A720DB98DD006C690F /* JXTAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JXTAlertView.m; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | A768DF821E0A6388005659B5 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXFrameworksBuildPhase section */ 45 | 46 | /* Begin PBXGroup section */ 47 | A768DF7C1E0A6388005659B5 = { 48 | isa = PBXGroup; 49 | children = ( 50 | A7AE309F20DB98DD006C690F /* JXTAlertManager */, 51 | A768DF871E0A6388005659B5 /* JXTAlertManagerDemo */, 52 | A768DF861E0A6388005659B5 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | A768DF861E0A6388005659B5 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | A768DF851E0A6388005659B5 /* JXTAlertManagerDemo.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | A768DF871E0A6388005659B5 /* JXTAlertManagerDemo */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | A768DF8B1E0A6388005659B5 /* AppDelegate.h */, 68 | A768DF8C1E0A6388005659B5 /* AppDelegate.m */, 69 | A768DF9F1E0A63BE005659B5 /* ShowViewController.h */, 70 | A768DFA01E0A63BE005659B5 /* ShowViewController.m */, 71 | A768DF941E0A6388005659B5 /* Assets.xcassets */, 72 | A768DF961E0A6388005659B5 /* LaunchScreen.storyboard */, 73 | A768DF991E0A6388005659B5 /* Info.plist */, 74 | A768DF881E0A6388005659B5 /* Supporting Files */, 75 | ); 76 | path = JXTAlertManagerDemo; 77 | sourceTree = ""; 78 | }; 79 | A768DF881E0A6388005659B5 /* Supporting Files */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | A768DF891E0A6388005659B5 /* main.m */, 83 | ); 84 | name = "Supporting Files"; 85 | sourceTree = ""; 86 | }; 87 | A7AE309F20DB98DD006C690F /* JXTAlertManager */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | A7AE30A320DB98DD006C690F /* JXTAlertManagerHeader.h */, 91 | A7AE30A020DB98DD006C690F /* AlertController */, 92 | A7AE30A420DB98DD006C690F /* AlertView */, 93 | ); 94 | name = JXTAlertManager; 95 | path = ../JXTAlertManager; 96 | sourceTree = ""; 97 | }; 98 | A7AE30A020DB98DD006C690F /* AlertController */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | A7AE30A120DB98DD006C690F /* JXTAlertController.h */, 102 | A7AE30A220DB98DD006C690F /* JXTAlertController.m */, 103 | ); 104 | path = AlertController; 105 | sourceTree = ""; 106 | }; 107 | A7AE30A420DB98DD006C690F /* AlertView */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | A7AE30A520DB98DD006C690F /* JXTAlertView.h */, 111 | A7AE30A720DB98DD006C690F /* JXTAlertView.m */, 112 | ); 113 | path = AlertView; 114 | sourceTree = ""; 115 | }; 116 | /* End PBXGroup section */ 117 | 118 | /* Begin PBXNativeTarget section */ 119 | A768DF841E0A6388005659B5 /* JXTAlertManagerDemo */ = { 120 | isa = PBXNativeTarget; 121 | buildConfigurationList = A768DF9C1E0A6388005659B5 /* Build configuration list for PBXNativeTarget "JXTAlertManagerDemo" */; 122 | buildPhases = ( 123 | A768DF811E0A6388005659B5 /* Sources */, 124 | A768DF821E0A6388005659B5 /* Frameworks */, 125 | A768DF831E0A6388005659B5 /* Resources */, 126 | ); 127 | buildRules = ( 128 | ); 129 | dependencies = ( 130 | ); 131 | name = JXTAlertManagerDemo; 132 | productName = JXTAlertManagerDemo; 133 | productReference = A768DF851E0A6388005659B5 /* JXTAlertManagerDemo.app */; 134 | productType = "com.apple.product-type.application"; 135 | }; 136 | /* End PBXNativeTarget section */ 137 | 138 | /* Begin PBXProject section */ 139 | A768DF7D1E0A6388005659B5 /* Project object */ = { 140 | isa = PBXProject; 141 | attributes = { 142 | LastUpgradeCheck = 0820; 143 | ORGANIZATIONNAME = JXT; 144 | TargetAttributes = { 145 | A768DF841E0A6388005659B5 = { 146 | CreatedOnToolsVersion = 8.2; 147 | ProvisioningStyle = Automatic; 148 | }; 149 | }; 150 | }; 151 | buildConfigurationList = A768DF801E0A6388005659B5 /* Build configuration list for PBXProject "JXTAlertManagerDemo" */; 152 | compatibilityVersion = "Xcode 3.2"; 153 | developmentRegion = English; 154 | hasScannedForEncodings = 0; 155 | knownRegions = ( 156 | en, 157 | Base, 158 | ); 159 | mainGroup = A768DF7C1E0A6388005659B5; 160 | productRefGroup = A768DF861E0A6388005659B5 /* Products */; 161 | projectDirPath = ""; 162 | projectRoot = ""; 163 | targets = ( 164 | A768DF841E0A6388005659B5 /* JXTAlertManagerDemo */, 165 | ); 166 | }; 167 | /* End PBXProject section */ 168 | 169 | /* Begin PBXResourcesBuildPhase section */ 170 | A768DF831E0A6388005659B5 /* Resources */ = { 171 | isa = PBXResourcesBuildPhase; 172 | buildActionMask = 2147483647; 173 | files = ( 174 | A768DF981E0A6388005659B5 /* LaunchScreen.storyboard in Resources */, 175 | A768DF951E0A6388005659B5 /* Assets.xcassets in Resources */, 176 | ); 177 | runOnlyForDeploymentPostprocessing = 0; 178 | }; 179 | /* End PBXResourcesBuildPhase section */ 180 | 181 | /* Begin PBXSourcesBuildPhase section */ 182 | A768DF811E0A6388005659B5 /* Sources */ = { 183 | isa = PBXSourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | A768DF8D1E0A6388005659B5 /* AppDelegate.m in Sources */, 187 | A7AE30A820DB98DD006C690F /* JXTAlertController.m in Sources */, 188 | A7AE30A920DB98DD006C690F /* JXTAlertView.m in Sources */, 189 | A768DF8A1E0A6388005659B5 /* main.m in Sources */, 190 | A768DFA11E0A63BE005659B5 /* ShowViewController.m in Sources */, 191 | ); 192 | runOnlyForDeploymentPostprocessing = 0; 193 | }; 194 | /* End PBXSourcesBuildPhase section */ 195 | 196 | /* Begin PBXVariantGroup section */ 197 | A768DF961E0A6388005659B5 /* LaunchScreen.storyboard */ = { 198 | isa = PBXVariantGroup; 199 | children = ( 200 | A768DF971E0A6388005659B5 /* Base */, 201 | ); 202 | name = LaunchScreen.storyboard; 203 | sourceTree = ""; 204 | }; 205 | /* End PBXVariantGroup section */ 206 | 207 | /* Begin XCBuildConfiguration section */ 208 | A768DF9A1E0A6388005659B5 /* Debug */ = { 209 | isa = XCBuildConfiguration; 210 | buildSettings = { 211 | ALWAYS_SEARCH_USER_PATHS = NO; 212 | CLANG_ANALYZER_NONNULL = YES; 213 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 214 | CLANG_CXX_LIBRARY = "libc++"; 215 | CLANG_ENABLE_MODULES = YES; 216 | CLANG_ENABLE_OBJC_ARC = YES; 217 | CLANG_WARN_BOOL_CONVERSION = YES; 218 | CLANG_WARN_CONSTANT_CONVERSION = YES; 219 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 220 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 221 | CLANG_WARN_EMPTY_BODY = YES; 222 | CLANG_WARN_ENUM_CONVERSION = YES; 223 | CLANG_WARN_INFINITE_RECURSION = YES; 224 | CLANG_WARN_INT_CONVERSION = YES; 225 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 226 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 227 | CLANG_WARN_UNREACHABLE_CODE = YES; 228 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 229 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 230 | COPY_PHASE_STRIP = NO; 231 | DEBUG_INFORMATION_FORMAT = dwarf; 232 | ENABLE_STRICT_OBJC_MSGSEND = YES; 233 | ENABLE_TESTABILITY = YES; 234 | GCC_C_LANGUAGE_STANDARD = gnu99; 235 | GCC_DYNAMIC_NO_PIC = NO; 236 | GCC_NO_COMMON_BLOCKS = YES; 237 | GCC_OPTIMIZATION_LEVEL = 0; 238 | GCC_PREPROCESSOR_DEFINITIONS = ( 239 | "DEBUG=1", 240 | "$(inherited)", 241 | ); 242 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 243 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 244 | GCC_WARN_UNDECLARED_SELECTOR = YES; 245 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 246 | GCC_WARN_UNUSED_FUNCTION = YES; 247 | GCC_WARN_UNUSED_VARIABLE = YES; 248 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 249 | MTL_ENABLE_DEBUG_INFO = YES; 250 | ONLY_ACTIVE_ARCH = YES; 251 | SDKROOT = iphoneos; 252 | TARGETED_DEVICE_FAMILY = "1,2"; 253 | }; 254 | name = Debug; 255 | }; 256 | A768DF9B1E0A6388005659B5 /* Release */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | ALWAYS_SEARCH_USER_PATHS = NO; 260 | CLANG_ANALYZER_NONNULL = YES; 261 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 262 | CLANG_CXX_LIBRARY = "libc++"; 263 | CLANG_ENABLE_MODULES = YES; 264 | CLANG_ENABLE_OBJC_ARC = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_CONSTANT_CONVERSION = YES; 267 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 268 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 269 | CLANG_WARN_EMPTY_BODY = YES; 270 | CLANG_WARN_ENUM_CONVERSION = YES; 271 | CLANG_WARN_INFINITE_RECURSION = YES; 272 | CLANG_WARN_INT_CONVERSION = YES; 273 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 274 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 278 | COPY_PHASE_STRIP = NO; 279 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 280 | ENABLE_NS_ASSERTIONS = NO; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | GCC_C_LANGUAGE_STANDARD = gnu99; 283 | GCC_NO_COMMON_BLOCKS = YES; 284 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 285 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 286 | GCC_WARN_UNDECLARED_SELECTOR = YES; 287 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 288 | GCC_WARN_UNUSED_FUNCTION = YES; 289 | GCC_WARN_UNUSED_VARIABLE = YES; 290 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 291 | MTL_ENABLE_DEBUG_INFO = NO; 292 | SDKROOT = iphoneos; 293 | TARGETED_DEVICE_FAMILY = "1,2"; 294 | VALIDATE_PRODUCT = YES; 295 | }; 296 | name = Release; 297 | }; 298 | A768DF9D1E0A6388005659B5 /* Debug */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 302 | INFOPLIST_FILE = JXTAlertManagerDemo/Info.plist; 303 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 304 | PRODUCT_BUNDLE_IDENTIFIER = JXT.JXTAlertManagerDemo; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | }; 307 | name = Debug; 308 | }; 309 | A768DF9E1E0A6388005659B5 /* Release */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 313 | INFOPLIST_FILE = JXTAlertManagerDemo/Info.plist; 314 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 315 | PRODUCT_BUNDLE_IDENTIFIER = JXT.JXTAlertManagerDemo; 316 | PRODUCT_NAME = "$(TARGET_NAME)"; 317 | }; 318 | name = Release; 319 | }; 320 | /* End XCBuildConfiguration section */ 321 | 322 | /* Begin XCConfigurationList section */ 323 | A768DF801E0A6388005659B5 /* Build configuration list for PBXProject "JXTAlertManagerDemo" */ = { 324 | isa = XCConfigurationList; 325 | buildConfigurations = ( 326 | A768DF9A1E0A6388005659B5 /* Debug */, 327 | A768DF9B1E0A6388005659B5 /* Release */, 328 | ); 329 | defaultConfigurationIsVisible = 0; 330 | defaultConfigurationName = Release; 331 | }; 332 | A768DF9C1E0A6388005659B5 /* Build configuration list for PBXNativeTarget "JXTAlertManagerDemo" */ = { 333 | isa = XCConfigurationList; 334 | buildConfigurations = ( 335 | A768DF9D1E0A6388005659B5 /* Debug */, 336 | A768DF9E1E0A6388005659B5 /* Release */, 337 | ); 338 | defaultConfigurationIsVisible = 0; 339 | defaultConfigurationName = Release; 340 | }; 341 | /* End XCConfigurationList section */ 342 | }; 343 | rootObject = A768DF7D1E0A6388005659B5 /* Project object */; 344 | } 345 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kukumaluCN/JXTAlertManager/acd2cfd7f2894a69670bc27878e293b56436ed72/JXTAlertManagerDemo/JXTAlertManagerDemo/.DS_Store -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JXTAlertManagerDemo 4 | // 5 | // Created by JXT on 2016/12/21. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JXTAlertManagerDemo 4 | // 5 | // Created by JXT on 2016/12/21. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 21 | self.window.backgroundColor = [UIColor whiteColor]; 22 | self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[NSClassFromString(@"ShowViewController") alloc] init]]; 23 | 24 | [self.window makeKeyAndVisible]; 25 | 26 | return YES; 27 | } 28 | 29 | 30 | - (void)applicationWillResignActive:(UIApplication *)application { 31 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 32 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 33 | } 34 | 35 | 36 | - (void)applicationDidEnterBackground:(UIApplication *)application { 37 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 38 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 39 | } 40 | 41 | 42 | - (void)applicationWillEnterForeground:(UIApplication *)application { 43 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 44 | } 45 | 46 | 47 | - (void)applicationDidBecomeActive:(UIApplication *)application { 48 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 49 | } 50 | 51 | 52 | - (void)applicationWillTerminate:(UIApplication *)application { 53 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 54 | } 55 | 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | zh_CN 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/ShowViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ShowViewController.h 3 | // JXTAlertManagerDemo 4 | // 5 | // Created by JXT on 2016/12/21. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ShowViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/ShowViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShowViewController.m 3 | // JXTAlertManagerDemo 4 | // 5 | // Created by JXT on 2016/12/21. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import "ShowViewController.h" 10 | 11 | #import "JXTAlertManagerHeader.h" 12 | 13 | static NSString *const cellId = @"CELLID"; 14 | 15 | @interface ShowViewController () 16 | @property (nonatomic, strong) UITableView * tableView; 17 | @property (nonatomic, strong) NSArray * sectionViewArray; 18 | @property (nonatomic, strong) NSArray * dataArray; 19 | @end 20 | 21 | @implementation ShowViewController 22 | 23 | #pragma mark - LifeCycle 24 | - (void)viewDidLoad 25 | { 26 | [super viewDidLoad]; 27 | 28 | self.navigationItem.title = @"JXTAlertManager"; 29 | 30 | self.dataArray = @[ 31 | @[ 32 | @"1.1.常规两个按钮alert", 33 | @"1.2.简易调试使用alert,单按钮,标题默认为“确定”", 34 | @"1.3.不定数量按钮alert", 35 | @"1.4.无按钮toast样式", 36 | @"1.5.单文字HUD", 37 | @"1.6.带indicatorView的HUD", 38 | @"1.7.带进度条的HUD,成功!", 39 | @"1.8.带进度条的HUD,失败!", 40 | ], 41 | @[ 42 | @"2.1.常规alertController-Alert", 43 | @"2.2.常规alertController-ActionSheet", 44 | @"2.3.无按钮alert-toast", 45 | @"2.4.无按钮actionSheet-toast", 46 | @"2.5.带输入框的alertController-Alert", 47 | ] 48 | ]; 49 | 50 | self.sectionViewArray = @[ 51 | [self labelWithText:@"1.AlertView-推荐日常调试使用"], 52 | [self labelWithText:@"2.AlertController-iOS8"] 53 | ]; 54 | 55 | [self.view addSubview:self.tableView]; 56 | } 57 | 58 | - (void)didReceiveMemoryWarning { 59 | [super didReceiveMemoryWarning]; 60 | } 61 | 62 | 63 | #pragma mark - UI 64 | - (UILabel *)labelWithText:(NSString *)text 65 | { 66 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 20)]; 67 | label.text = text; 68 | label.font = [UIFont boldSystemFontOfSize:20]; 69 | label.backgroundColor = [[self randomColor] colorWithAlphaComponent:0.5]; 70 | label.textAlignment = NSTextAlignmentCenter; 71 | 72 | return label; 73 | } 74 | - (UITableView *)tableView 75 | { 76 | if (!_tableView) { 77 | if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) { 78 | self.automaticallyAdjustsScrollViewInsets = NO; 79 | } 80 | _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; 81 | _tableView.delegate = self; 82 | _tableView.dataSource = self; 83 | _tableView.backgroundColor = [UIColor whiteColor]; 84 | _tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0); 85 | _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(64, 0, 0, 0); 86 | 87 | if (@available(iOS 11.0, *)) { 88 | _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; 89 | } else { 90 | // Fallback on earlier versions 91 | 92 | } 93 | } 94 | return _tableView; 95 | } 96 | 97 | 98 | #pragma mark - UITableViewDataSource 99 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 100 | { 101 | return self.dataArray.count; 102 | } 103 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 104 | { 105 | NSArray *sectionArray = self.dataArray[section]; 106 | return sectionArray.count; 107 | } 108 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 109 | { 110 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 111 | if (!cell) { 112 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; 113 | } 114 | cell.backgroundColor = [self randomColor]; 115 | cell.textLabel.text = self.dataArray[indexPath.section][indexPath.row]; 116 | cell.textLabel.numberOfLines = 0; 117 | 118 | return cell; 119 | } 120 | //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 121 | //{ 122 | // return @"title"; 123 | //} 124 | 125 | #pragma mark - UITableViewDelegate 126 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 127 | { 128 | return 70; 129 | } 130 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 131 | { 132 | return 25; 133 | } 134 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 135 | { 136 | return 0.01; 137 | } 138 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 139 | { 140 | return self.sectionViewArray[section]; 141 | } 142 | 143 | #pragma mark alert使用示例 144 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 145 | { 146 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 147 | 148 | if (indexPath.section == 0) 149 | { 150 | if (indexPath.row == 0) 151 | { 152 | //1. 153 | // [JXTAlertView showAlertViewWithTitle:@"title" message:@"message" cancelButtonTitle:@"cancel" otherButtonTitle:@"other" cancelButtonBlock:^(NSInteger buttonIndex) { 154 | // NSLog(@"cancel"); 155 | // } otherButtonBlock:^(NSInteger buttonIndex) { 156 | // NSLog(@"other"); 157 | // }]; 158 | //2. 159 | jxt_showAlertTwoButton(@"常规两个按钮alert", @"支持按钮点击回调,支持C函数快速调用", @"cancel", ^(NSInteger buttonIndex) { 160 | NSLog(@"cancel"); 161 | }, @"other", ^(NSInteger buttonIndex) { 162 | NSLog(@"other"); 163 | }); 164 | } 165 | else if (indexPath.row == 1) 166 | { 167 | jxt_showAlertTitle(@"简易调试使用alert,单按钮,标题默认为“确定”"); 168 | } 169 | else if (indexPath.row == 2) 170 | { 171 | [JXTAlertView showAlertViewWithTitle:@"不定数量按钮alert" message:@"支持按钮点击回调,根据按钮index区分响应,有cancel按钮时,cancel的index默认0,无cancel时,按钮index根据添加顺序计算" cancelButtonTitle:@"cancel" buttonIndexBlock:^(NSInteger buttonIndex) { 172 | if (buttonIndex == 0) { 173 | NSLog(@"cancel"); 174 | } 175 | else if (buttonIndex == 1) { 176 | NSLog(@"按钮1"); 177 | } 178 | else if (buttonIndex == 2) { 179 | NSLog(@"按钮2"); 180 | } 181 | else if (buttonIndex == 3) { 182 | NSLog(@"按钮3"); 183 | } 184 | else if (buttonIndex == 4) { 185 | NSLog(@"按钮4"); 186 | } 187 | else if (buttonIndex == 5) { 188 | NSLog(@"按钮5"); 189 | } 190 | } otherButtonTitles:@"按钮1", @"按钮2", @"按钮3", @"按钮4", @"按钮5", nil]; 191 | } 192 | else if (indexPath.row == 3) 193 | { 194 | //1. 195 | [JXTAlertView showToastViewWithTitle:@"无按钮toast样式" message:@"可自定义展示延时时间,支持关闭回调" duration:2 dismissCompletion:^(NSInteger buttonIndex) { 196 | NSLog(@"关闭"); 197 | }]; 198 | //2. 199 | // jxt_showToastTitleDismiss(@"无按钮toast样式", 2, ^(NSInteger buttonIndex) { 200 | // NSLog(@"关闭"); 201 | // }); 202 | //3. 203 | // jxt_showToastMessage(@"无按钮toast样式", 0); 204 | } 205 | else if (indexPath.row == 4) 206 | { 207 | //1. 208 | // jxt_showTextHUDTitle(@"单文字HUD"); 209 | //2. 210 | jxt_showTextHUDTitleMessage(@"单文字HUD", @"支持子标题,手动执行关闭,可改变显示状态"); 211 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 212 | jxt_dismissHUD(); 213 | }); 214 | } 215 | else if (indexPath.row == 5) 216 | { 217 | jxt_showLoadingHUDTitleMessage(@"带indicatorView的HUD", @"支持子标题,手动执行关闭,可改变显示状态"); 218 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 219 | jxt_dismissHUD(); 220 | }); 221 | } 222 | else if (indexPath.row == 6) 223 | { 224 | jxt_showProgressHUDTitleMessage(@"带进度条的HUD", @"支持子标题,手动执行关闭,可改变显示状态"); 225 | __block float count = 0; 226 | #warning timer block ios10 only 227 | [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) { 228 | count += 0.05; 229 | jxt_setHUDProgress(count); 230 | if (count > 1) { 231 | [timer invalidate]; 232 | jxt_setHUDSuccessTitle(@"加载成功!"); 233 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 234 | jxt_dismissHUD(); 235 | }); 236 | } 237 | }]; 238 | } 239 | else if (indexPath.row == 7) 240 | { 241 | jxt_showProgressHUDTitleMessage(@"带进度条的HUD", @"支持子标题,手动执行关闭,可改变显示状态"); 242 | __block float count = 0; 243 | #warning timer block ios10 only 244 | [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) { 245 | count += 0.05; 246 | jxt_setHUDProgress(count); 247 | if (count > 1) { 248 | [timer invalidate]; 249 | jxt_setHUDFailMessage(@"加载失败!"); 250 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 251 | jxt_dismissHUD(); 252 | }); 253 | } 254 | }]; 255 | } 256 | } 257 | else if (indexPath.section == 1) 258 | { 259 | if (indexPath.row == 0) 260 | { 261 | [self jxt_showAlertWithTitle:@"常规alertController-Alert" message:@"基于系统UIAlertController封装,按钮以链式语法模式快捷添加,可根据按钮index区分响应,可根据action区分响应,支持配置弹出、关闭回调,可关闭弹出动画" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 262 | alertMaker. 263 | addActionCancelTitle(@"cancel"). 264 | addActionDestructiveTitle(@"按钮1"); 265 | } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { 266 | if (buttonIndex == 0) { 267 | NSLog(@"cancel"); 268 | } 269 | else if (buttonIndex == 1) { 270 | NSLog(@"按钮1"); 271 | } 272 | NSLog(@"%@--%@", action.title, action); 273 | }]; 274 | } 275 | else if (indexPath.row == 1) 276 | { 277 | [self jxt_showActionSheetWithTitle:@"常规alertController-ActionSheet" message:@"基于系统UIAlertController封装,按钮以链式语法模式快捷添加,可根据按钮index区分响应,可根据action区分响应,支持配置弹出、关闭回调,可关闭弹出动画" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 278 | alertMaker. 279 | addActionCancelTitle(@"cancel"). 280 | addActionDestructiveTitle(@"按钮1"). 281 | addActionDefaultTitle(@"按钮2"). 282 | addActionDefaultTitle(@"按钮3"). 283 | addActionDestructiveTitle(@"按钮4"); 284 | } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { 285 | 286 | if ([action.title isEqualToString:@"cancel"]) { 287 | NSLog(@"cancel"); 288 | } 289 | else if ([action.title isEqualToString:@"按钮1"]) { 290 | NSLog(@"按钮1"); 291 | } 292 | else if ([action.title isEqualToString:@"按钮2"]) { 293 | NSLog(@"按钮2"); 294 | } 295 | else if ([action.title isEqualToString:@"按钮3"]) { 296 | NSLog(@"按钮3"); 297 | } 298 | else if ([action.title isEqualToString:@"按钮4"]) { 299 | NSLog(@"按钮4"); 300 | } 301 | }]; 302 | } 303 | else if (indexPath.row == 2) 304 | { 305 | [self jxt_showAlertWithTitle:@"无按钮alert-toast" message:@"toast样式,可自定义展示延时时间,支持配置弹出、关闭回调,可关闭弹出动画" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 306 | alertMaker.toastStyleDuration = 2; 307 | [alertMaker setAlertDidShown:^{ 308 | [self logMsg:@"alertDidShown"];//不用担心循环引用 309 | }]; 310 | alertMaker.alertDidDismiss = ^{ 311 | [self logMsg:@"alertDidDismiss"]; 312 | }; 313 | } actionsBlock:NULL]; 314 | } 315 | else if (indexPath.row == 3) 316 | { 317 | [self jxt_showActionSheetWithTitle:@"无按钮actionSheet-toast" message:@"toast样式,可自定义展示延时时间,支持配置弹出、关闭回调,可关闭弹出动画" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 318 | alertMaker.toastStyleDuration = 3; 319 | //关闭动画效果 320 | [alertMaker alertAnimateDisabled]; 321 | 322 | [alertMaker setAlertDidShown:^{ 323 | NSLog(@"alertDidShown"); 324 | }]; 325 | alertMaker.alertDidDismiss = ^{ 326 | NSLog(@"alertDidDismiss"); 327 | }; 328 | } actionsBlock:NULL]; 329 | } 330 | else if (indexPath.row == 4) 331 | { 332 | [self jxt_showAlertWithTitle:@"带输入框的alertController-Alert" message:@"点击按钮,控制台打印对应输入框的内容" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 333 | alertMaker. 334 | addActionDestructiveTitle(@"获取输入框1"). 335 | addActionDestructiveTitle(@"获取输入框2"); 336 | 337 | [alertMaker addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 338 | textField.placeholder = @"输入框1-请输入"; 339 | }]; 340 | [alertMaker addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 341 | textField.placeholder = @"输入框2-请输入"; 342 | }]; 343 | } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { 344 | if (buttonIndex == 0) { 345 | UITextField *textField = alertSelf.textFields.firstObject; 346 | [self logMsg:textField.text];//不用担心循环引用 347 | } 348 | else if (buttonIndex == 1) { 349 | UITextField *textField = alertSelf.textFields.lastObject; 350 | [self logMsg:textField.text]; 351 | } 352 | }]; 353 | } 354 | } 355 | } 356 | 357 | 358 | #pragma mark - Methods 359 | - (void)logMsg:(NSString *)msg 360 | { 361 | NSLog(@"%@", msg); 362 | } 363 | - (UIColor *)randomColor 364 | { 365 | CGFloat r = arc4random_uniform(255); 366 | CGFloat g = arc4random_uniform(255); 367 | CGFloat b = arc4random_uniform(255); 368 | 369 | return [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:0.3f]; 370 | } 371 | 372 | @end 373 | -------------------------------------------------------------------------------- /JXTAlertManagerDemo/JXTAlertManagerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JXTAlertManagerDemo 4 | // 5 | // Created by JXT on 2016/12/21. 6 | // Copyright © 2016年 JXT. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 JXT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JXTAlertManager 2 | 3 | [![CocoaPods compatible](https://img.shields.io/cocoapods/v/JXTAlertManager.svg?style=flat)](https://cocoapods.org/pods/JXTAlertManager)  4 | [![Support](https://img.shields.io/badge/support-iOS%208%2B%20-green.svg?style=flat)](https://www.apple.com/nl/ios/)  5 | [![License: MIT](https://img.shields.io/cocoapods/l/JXTAlertManager.svg?style=flat)](http://opensource.org/licenses/MIT) 6 | 7 | 8 | > 更新说明: 9 | > CocoaPods支持: 10 | > 1. 在 Podfile 中添加 pod 'JXTAlertManager'。 11 | > 2. 执行 pod install 或 pod update。 12 | > 3. 导入 \。 13 | 14 | 15 | > 如果只需要JXTAlertController,见[JXTAlertController](https://github.com/kukumaluCN/JXTAlertController) 16 | 17 | 18 | UIAlertView/UIAlertController便捷调用工具 19 | 基于系统UIAlertView/UIAlertController封装,简化使用 20 | 详细用法参考Demo 21 | ![JXTAlertManager](https://github.com/kukumaluCN/JXTAlertManager/blob/master/JXTAlertManager.png) 22 | 23 | ## JXTAlertView 24 | 25 | ### 1.快速调试工具 26 | ```objective-c 27 | jxt_showAlertTitle(@"简易调试使用alert,单按钮,标题默认为“确定”"); 28 | ``` 29 | 30 | ### 2.两个按钮 31 | ```objective-c 32 | [JXTAlertView showAlertViewWithTitle:@"title" message:@"message" cancelButtonTitle:@"cancel" otherButtonTitle:@"other" cancelButtonBlock:^(NSInteger buttonIndex) { 33 | NSLog(@"cancel"); 34 | } otherButtonBlock:^(NSInteger buttonIndex) { 35 | NSLog(@"other"); 36 | }]; 37 | 38 | ``` 39 | 40 | ### 3.不定数量按钮 41 | ```objective-c 42 | [JXTAlertView showAlertViewWithTitle:@"title" 43 | message:@"message" 44 | cancelButtonTitle:@"cancel" 45 | buttonIndexBlock:^(NSInteger buttonIndex) { 46 | if (buttonIndex == 0) { 47 | NSLog(@"cancel"); 48 | } 49 | else if (buttonIndex == 1) { 50 | NSLog(@"按钮1"); 51 | } 52 | else if (buttonIndex == 2) { 53 | NSLog(@"按钮2"); 54 | } 55 | else if (buttonIndex == 3) { 56 | NSLog(@"按钮3"); 57 | } 58 | else if (buttonIndex == 4) { 59 | NSLog(@"按钮4"); 60 | } 61 | else if (buttonIndex == 5) { 62 | NSLog(@"按钮5"); 63 | } 64 | } otherButtonTitles:@"按钮1", @"按钮2", @"按钮3", @"按钮4", @"按钮5", nil]; 65 | ``` 66 | 67 | ### 4.HUD 68 | ```objective-c 69 | jxt_showLoadingHUDTitleMessage(@"indicatorView-HUD", @"message"); 70 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 71 | jxt_dismissHUD(); 72 | }); 73 | ``` 74 | 75 | 76 | ## JXTAlertController(iOS8) 77 | 78 | ### 1.alert 79 | ```objective-c 80 | [self jxt_showAlertWithTitle:@"title" 81 | message:@"message" 82 | appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 83 | alertMaker. 84 | addActionCancelTitle(@"cancel"). 85 | addActionDestructiveTitle(@"按钮1"); 86 | } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { 87 | if (buttonIndex == 0) { 88 | NSLog(@"cancel"); 89 | } 90 | else if (buttonIndex == 1) { 91 | NSLog(@"按钮1"); 92 | } 93 | }]; 94 | ``` 95 | 96 | ### 2.添加textField 97 | ```objective-c 98 | [self jxt_showAlertWithTitle:@"title" 99 | message:@"message" 100 | appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { 101 | alertMaker. 102 | addActionDestructiveTitle(@"获取输入框1"). 103 | addActionDestructiveTitle(@"获取输入框2"); 104 | 105 | [alertMaker addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 106 | textField.placeholder = @"输入框1-请输入"; 107 | }]; 108 | [alertMaker addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 109 | textField.placeholder = @"输入框2-请输入"; 110 | }]; 111 | } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { 112 | if (buttonIndex == 0) { 113 | UITextField *textField = alertSelf.textFields.firstObject; 114 | [self logMsg:textField.text];//不用担心循环引用 115 | } 116 | else if (buttonIndex == 1) { 117 | UITextField *textField = alertSelf.textFields.lastObject; 118 | [self logMsg:textField.text]; 119 | } 120 | }]; 121 | ``` 122 | --------------------------------------------------------------------------------