From 21d3023a9b7b6aff68c1170e345951396b1c6cfd Mon Sep 17 00:00:00 2001 From: 单军华 Date: Tue, 31 Jul 2018 13:35:21 +0800 Subject: [PATCH] no message --- screendisplay/screendisplay/Classes/Helpers/JXTAlertController.h | 535 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 535 insertions(+), 0 deletions(-) diff --git a/screendisplay/screendisplay/Classes/Helpers/JXTAlertController.h b/screendisplay/screendisplay/Classes/Helpers/JXTAlertController.h new file mode 100755 index 0000000..1a5c806 --- /dev/null +++ b/screendisplay/screendisplay/Classes/Helpers/JXTAlertController.h @@ -0,0 +1,535 @@ +// +// JXTAlertController.h +// JXTAlertManager +// +// Created by JXT on 2016/12/22. +// Copyright �� 2016��� JXT. All rights reserved. +// + +#import <UIKit/UIKit.h> + + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark - I.JXTAlertController������ + +@class JXTAlertController; +/** + JXTAlertController: alertAction��������� + + @param title ������ + @return JXTAlertController������ + */ +typedef JXTAlertController * _Nonnull (^JXTAlertActionTitle)(NSString *title); + +/** + JXTAlertController: alert������������������ + + @param buttonIndex ������index(������������action���������) + @param action UIAlertAction������ + @param alertSelf ������������ + */ +typedef void (^JXTAlertActionBlock)(NSInteger buttonIndex, UIAlertAction *action, JXTAlertController *alertSelf); + + +/** + JXTAlertController ��������� + + 1.������������UIAlertController���������������iOS8��������� + + 2.������iOS9���������`preferredAction`������������: + `alertController.preferredAction = alertController.actions[0];` + ������������������������������action������������������cancel���������������������������deafult���������cancel���������action��������������������� + ���������������������������������`UIAlertControllerStyleAlert`���actionSheet������������������������������������������������ + + 3.������`addTextFieldWithConfigurationHandler:`������: + ������������������������`UIAlertControllerStyleAlert`��������������������������������������������������������������������������� + + 4.������������������������������������������������������kvc������������������������������������������������ + `[alertAction setValue:[UIColor grayColor] forKey:@"titleTextColor"]` + */ +NS_CLASS_AVAILABLE_IOS(8_0) @interface JXTAlertController : UIAlertController + + +/** + JXTAlertController: ������alert������������������������������������������������������ + */ +- (void)alertAnimateDisabled; + +/** + JXTAlertController: alert������������������������������ + */ +@property (nullable, nonatomic, copy) void (^alertDidShown)(void); + +/** + JXTAlertController: alert������������������������������ + */ +@property (nullable, nonatomic, copy) void (^alertDidDismiss)(void); + +/** + JXTAlertController: ������toast���������������������������alert���������������������������������toast������������������������������������������������1s + */ +@property (nonatomic, assign) NSTimeInterval toastStyleDuration; //deafult jxt_alertShowDurationDefault = 1s + + +/** + JXTAlertController: ������������alert���������������������������alertAction��������������������������������������� + + @return JXTAlertController������ + */ +- (JXTAlertActionTitle)addActionDefaultTitle; + +/** + JXTAlertController: ������������alert���������������������������alertAction���������������������������������������(warning:������alert���������������������������!!!) + + @return JXTAlertController������ + */ +- (JXTAlertActionTitle)addActionCancelTitle; + +/** + JXTAlertController: ������������alert���������������������������alertAction��������������������������������������� + + @return JXTAlertController������ + */ +- (JXTAlertActionTitle)addActionDestructiveTitle; + +@end + + +#pragma mark - II.UIViewController������������JXTAlertController + +/** + JXTAlertController: alert��������� + + @param alertMaker JXTAlertController������������ + */ +typedef void(^JXTAlertAppearanceProcess)(JXTAlertController *alertMaker); + +@interface UIViewController (JXTAlertController) + +/** + JXTAlertController: show-alert(iOS8) + + @param title title + @param message message + @param appearanceProcess alert������������ + @param actionBlock alert������������������ + */ +- (void)jxt_showAlertWithTitle:(nullable NSString *)title + message:(nullable NSString *)message + appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess + actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0); + +/** + JXTAlertController: show-actionSheet(iOS8) + + @param title title + @param message message + @param appearanceProcess actionSheet������������ + @param actionBlock actionSheet������������������ + */ +- (void)jxt_showActionSheetWithTitle:(nullable NSString *)title + message:(nullable NSString *)message + appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess + actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0); + +@end + +@interface UIAlertController (LMJ) +/** + JXTAlertController: show-alert(iOS8) + + @param title title + @param message message + @param appearanceProcess alert������������ + @param actionBlock alert������������������ + */ ++ (void)mj_showAlertWithTitle:(nullable NSString *)title + message:(nullable NSString *)message + appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess + actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0); + +/** + JXTAlertController: show-actionSheet(iOS8) + + @param title title + @param message message + @param appearanceProcess actionSheet������������ + @param actionBlock actionSheet������������������ + */ ++ (void)mj_showActionSheetWithTitle:(nullable NSString *)title + message:(nullable NSString *)message + appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess + actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0); +@end + +NS_ASSUME_NONNULL_END +/* + // + // ShowViewController.m + // JXTAlertManagerDemo + // + // Created by JXT on 2016/12/21. + // Copyright �� 2016��� JXT. All rights reserved. + // + + #import "ShowViewController.h" + + #import "JXTAlertManagerHeader.h" + + static NSString *const cellId = @"CELLID"; + + @interface ShowViewController () <UITableViewDataSource, UITableViewDelegate> + @property (nonatomic, strong) UITableView * tableView; + @property (nonatomic, strong) NSArray * sectionViewArray; + @property (nonatomic, strong) NSArray * dataArray; + @end + + @implementation ShowViewController + + #pragma mark - LifeCycle + - (void)viewDidLoad + { + [super viewDidLoad]; + + self.navigationItem.title = @"JXTAlertManager"; + + self.dataArray = @[ + @[ + @"1.1.������������������alert", + @"1.2.������������������alert������������������������������������������", + @"1.3.������������������alert", + @"1.4.���������toast������", + @"1.5.���������HUD", + @"1.6.���indicatorView���HUD", + @"1.7.���������������HUD������������", + @"1.8.���������������HUD������������", + ], + @[ + @"2.1.������alertController-Alert", + @"2.2.������alertController-ActionSheet", + @"2.3.���������alert-toast", + @"2.4.���������actionSheet-toast", + @"2.5.���������������alertController-Alert", + ] + ]; + + self.sectionViewArray = @[ + [self labelWithText:@"1.AlertView-������������������������"], + [self labelWithText:@"2.AlertController-iOS8"] + ]; + + [self.view addSubview:self.tableView]; + } + + - (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + } + + + #pragma mark - UI + - (UILabel *)labelWithText:(NSString *)text + { + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 20)]; + label.text = text; + label.font = [UIFont boldSystemFontOfSize:20]; + label.backgroundColor = [[self randomColor] colorWithAlphaComponent:0.5]; + label.textAlignment = NSTextAlignmentCenter; + + return label; + } + - (UITableView *)tableView + { + if (!_tableView) { + if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) { + self.automaticallyAdjustsScrollViewInsets = NO; + } + _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; + _tableView.delegate = self; + _tableView.dataSource = self; + _tableView.backgroundColor = [UIColor whiteColor]; + _tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0); + _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(64, 0, 0, 0); + } + return _tableView; + } + + + #pragma mark - UITableViewDataSource + - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView + { + return self.dataArray.count; + } + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section + { + NSArray *sectionArray = self.dataArray[section]; + return sectionArray.count; + } + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath + { + UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; + } + cell.backgroundColor = [self randomColor]; + cell.textLabel.text = self.dataArray[indexPath.section][indexPath.row]; + cell.textLabel.numberOfLines = 0; + + return cell; + } + //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section + //{ + // return @"title"; + //} + + #pragma mark - UITableViewDelegate + - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath + { + return 70; + } + - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section + { + return 25; + } + - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section + { + return 0.01; + } + - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section + { + return self.sectionViewArray[section]; + } + + #pragma mark alert������������ + - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath + { + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + + if (indexPath.section == 0) + { + if (indexPath.row == 0) + { + //1. + // [JXTAlertView showAlertViewWithTitle:@"title" message:@"message" cancelButtonTitle:@"cancel" otherButtonTitle:@"other" cancelButtonBlock:^(NSInteger buttonIndex) { + // NSLog(@"cancel"); + // } otherButtonBlock:^(NSInteger buttonIndex) { + // NSLog(@"other"); + // }]; + //2. + jxt_showAlertTwoButton(@"������������������alert", @"���������������������������������C������������������", @"cancel", ^(NSInteger buttonIndex) { + NSLog(@"cancel"); + }, @"other", ^(NSInteger buttonIndex) { + NSLog(@"other"); + }); + } + else if (indexPath.row == 1) + { + jxt_showAlertTitle(@"������������������alert������������������������������������������"); + } + else if (indexPath.row == 2) + { + [JXTAlertView showAlertViewWithTitle:@"������������������alert" message:@"���������������������������������������index������������������cancel������������cancel���index������0������cancel������������index������������������������" cancelButtonTitle:@"cancel" buttonIndexBlock:^(NSInteger buttonIndex) { + if (buttonIndex == 0) { + NSLog(@"cancel"); + } + else if (buttonIndex == 1) { + NSLog(@"������1"); + } + else if (buttonIndex == 2) { + NSLog(@"������2"); + } + else if (buttonIndex == 3) { + NSLog(@"������3"); + } + else if (buttonIndex == 4) { + NSLog(@"������4"); + } + else if (buttonIndex == 5) { + NSLog(@"������5"); + } + } otherButtonTitles:@"������1", @"������2", @"������3", @"������4", @"������5", nil]; + } + else if (indexPath.row == 3) + { + //1. + [JXTAlertView showToastViewWithTitle:@"���������toast������" message:@"���������������������������������������������������" duration:2 dismissCompletion:^(NSInteger buttonIndex) { + NSLog(@"������"); + }]; + //2. + // jxt_showToastTitleDismiss(@"���������toast������", 2, ^(NSInteger buttonIndex) { + // NSLog(@"������"); + // }); + //3. + // jxt_showToastMessage(@"���������toast������", 0); + } + else if (indexPath.row == 4) + { + //1. + // jxt_showTextHUDTitle(@"���������HUD"); + //2. + jxt_showTextHUDTitleMessage(@"���������HUD", @"������������������������������������������������������������"); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + jxt_dismissHUD(); + }); + } + else if (indexPath.row == 5) + { + jxt_showLoadingHUDTitleMessage(@"���indicatorView���HUD", @"������������������������������������������������������������"); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + jxt_dismissHUD(); + }); + } + else if (indexPath.row == 6) + { + jxt_showProgressHUDTitleMessage(@"���������������HUD", @"������������������������������������������������������������"); + __block float count = 0; + #warning timer block ios10 only + [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) { + count += 0.05; + jxt_setHUDProgress(count); + if (count > 1) { + [timer invalidate]; + jxt_setHUDSuccessTitle(@"���������������"); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + jxt_dismissHUD(); + }); + } + }]; + } + else if (indexPath.row == 7) + { + jxt_showProgressHUDTitleMessage(@"���������������HUD", @"������������������������������������������������������������"); + __block float count = 0; + #warning timer block ios10 only + [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) { + count += 0.05; + jxt_setHUDProgress(count); + if (count > 1) { + [timer invalidate]; + jxt_setHUDFailMessage(@"���������������"); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + jxt_dismissHUD(); + }); + } + }]; + } + } + else if (indexPath.section == 1) + { + if (indexPath.row == 0) + { + [self jxt_showAlertWithTitle:@"������alertController-Alert" message:@"������������UIAlertController������������������������������������������������������������������index������������������������action������������������������������������������������������������������������" 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"); + } + NSLog(@"%@--%@", action.title, action); + }]; + } + else if (indexPath.row == 1) + { + [self jxt_showActionSheetWithTitle:@"������alertController-ActionSheet" message:@"������������UIAlertController������������������������������������������������������������������index������������������������action������������������������������������������������������������������������" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { + alertMaker. + addActionCancelTitle(@"cancel"). + addActionDestructiveTitle(@"������1"). + addActionDefaultTitle(@"������2"). + addActionDefaultTitle(@"������3"). + addActionDestructiveTitle(@"������4"); + } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { + + if ([action.title isEqualToString:@"cancel"]) { + NSLog(@"cancel"); + } + else if ([action.title isEqualToString:@"������1"]) { + NSLog(@"������1"); + } + else if ([action.title isEqualToString:@"������2"]) { + NSLog(@"������2"); + } + else if ([action.title isEqualToString:@"������3"]) { + NSLog(@"������3"); + } + else if ([action.title isEqualToString:@"������4"]) { + NSLog(@"������4"); + } + }]; + } + else if (indexPath.row == 2) + { + [self jxt_showAlertWithTitle:@"���������alert-toast" message:@"toast���������������������������������������������������������������������������������������������������" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { + alertMaker.toastStyleDuration = 2; + [alertMaker setAlertDidShown:^{ + [self logMsg:@"alertDidShown"];//������������������������ + }]; + alertMaker.alertDidDismiss = ^{ + [self logMsg:@"alertDidDismiss"]; + }; + } actionsBlock:NULL]; + } + else if (indexPath.row == 3) + { + [self jxt_showActionSheetWithTitle:@"���������actionSheet-toast" message:@"toast���������������������������������������������������������������������������������������������������" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { + alertMaker.toastStyleDuration = 3; + //������������������ + [alertMaker alertAnimateDisabled]; + + [alertMaker setAlertDidShown:^{ + NSLog(@"alertDidShown"); + }]; + alertMaker.alertDidDismiss = ^{ + NSLog(@"alertDidDismiss"); + }; + } actionsBlock:NULL]; + } + else if (indexPath.row == 4) + { + [self jxt_showAlertWithTitle:@"���������������alertController-Alert" 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]; + } + }]; + } + } + } + + + #pragma mark - Methods + - (void)logMsg:(NSString *)msg + { + NSLog(@"%@", msg); + } + - (UIColor *)randomColor + { + CGFloat r = arc4random_uniform(255); + CGFloat g = arc4random_uniform(255); + CGFloat b = arc4random_uniform(255); + + return [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:0.3f]; + } + + @end + + */ + -- Gitblit v1.8.0