From 81a2dd0d903f3443eb6fe271412e6b9699ca639c Mon Sep 17 00:00:00 2001 From: JXT Date: Fri, 22 Jun 2018 15:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JXTAlertController/JXTAlertController.h | 138 +++++++ JXTAlertController/JXTAlertController.m | 216 +++++++++++ .../project.pbxproj | 341 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../JXTAlertControllerDemo/AppDelegate.h | 17 + .../JXTAlertControllerDemo/AppDelegate.m | 57 +++ .../AppIcon.appiconset/Contents.json | 98 +++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 31 ++ .../DemoViewController.h | 13 + .../DemoViewController.m | 216 +++++++++++ .../JXTAlertControllerDemo/Info.plist | 40 ++ .../JXTAlertControllerDemo/main.m | 16 + JXTAlertManager.podspec | 34 ++ 15 files changed, 1238 insertions(+) create mode 100644 JXTAlertController/JXTAlertController.h create mode 100644 JXTAlertController/JXTAlertController.m create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.pbxproj create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.h create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.m create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/Contents.json create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/Base.lproj/LaunchScreen.storyboard create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.h create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.m create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/Info.plist create mode 100644 JXTAlertControllerDemo/JXTAlertControllerDemo/main.m create mode 100644 JXTAlertManager.podspec diff --git a/JXTAlertController/JXTAlertController.h b/JXTAlertController/JXTAlertController.h new file mode 100644 index 0000000..1040abf --- /dev/null +++ b/JXTAlertController/JXTAlertController.h @@ -0,0 +1,138 @@ +// +// JXTAlertController.h +// JXTAlertManager +// +// Created by JXT on 2016/12/22. +// Copyright © 2016年 JXT. All rights reserved. +// + +#import + + +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 + +NS_ASSUME_NONNULL_END diff --git a/JXTAlertController/JXTAlertController.m b/JXTAlertController/JXTAlertController.m new file mode 100644 index 0000000..29613b5 --- /dev/null +++ b/JXTAlertController/JXTAlertController.m @@ -0,0 +1,216 @@ +// +// JXTAlertController.m +// JXTAlertManager +// +// Created by JXT on 2016/12/22. +// Copyright © 2016年 JXT. All rights reserved. +// + +#import "JXTAlertController.h" + +//toast默认展示时间 +static NSTimeInterval const JXTAlertShowDurationDefault = 1.0f; + + +#pragma mark - I.AlertActionModel +@interface JXTAlertActionModel : NSObject +@property (nonatomic, copy) NSString * title; +@property (nonatomic, assign) UIAlertActionStyle style; +@end +@implementation JXTAlertActionModel +- (instancetype)init +{ + if (self = [super init]) { + self.title = @""; + self.style = UIAlertActionStyleDefault; + } + return self; +} +@end + + + +#pragma mark - II.JXTAlertController +/** + AlertActions配置 + + @param actionBlock JXTAlertActionBlock + */ +typedef void (^JXTAlertActionsConfig)(JXTAlertActionBlock actionBlock); + + +@interface JXTAlertController () +//JXTAlertActionModel数组 +@property (nonatomic, strong) NSMutableArray * jxt_alertActionArray; +//是否操作动画 +@property (nonatomic, assign) BOOL jxt_setAlertAnimated; +//action配置 +- (JXTAlertActionsConfig)alertActionsConfig; +@end + +@implementation JXTAlertController + +- (void)viewDidLoad { + [super viewDidLoad]; +} +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; +} +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + if (self.alertDidDismiss) { + self.alertDidDismiss(); + } +} +- (void)dealloc +{ +// NSLog(@"test-dealloc"); +} + +#pragma mark - Private +//action-title数组 +- (NSMutableArray *)jxt_alertActionArray +{ + if (_jxt_alertActionArray == nil) { + _jxt_alertActionArray = [NSMutableArray array]; + } + return _jxt_alertActionArray; +} +//action配置 +- (JXTAlertActionsConfig)alertActionsConfig +{ + return ^(JXTAlertActionBlock actionBlock) { + if (self.jxt_alertActionArray.count > 0) + { + //创建action + __weak typeof(self)weakSelf = self; + [self.jxt_alertActionArray enumerateObjectsUsingBlock:^(JXTAlertActionModel *actionModel, NSUInteger idx, BOOL * _Nonnull stop) { + UIAlertAction *alertAction = [UIAlertAction actionWithTitle:actionModel.title style:actionModel.style handler:^(UIAlertAction * _Nonnull action) { + __strong typeof(weakSelf)strongSelf = weakSelf; + if (actionBlock) { + actionBlock(idx, action, strongSelf); + } + }]; + //可利用这个改变字体颜色,但是不推荐!!! +// [alertAction setValue:[UIColor grayColor] forKey:@"titleTextColor"]; + //action作为self元素,其block实现如果引用本类指针,会造成循环引用 + [self addAction:alertAction]; + }]; + } + else + { + NSTimeInterval duration = self.toastStyleDuration > 0 ? self.toastStyleDuration : JXTAlertShowDurationDefault; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self dismissViewControllerAnimated:!(self.jxt_setAlertAnimated) completion:NULL]; + }); + } + }; +} + +#pragma mark - Public + +- (instancetype)initAlertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle +{ + if (!(title.length > 0) && (message.length > 0) && (preferredStyle == UIAlertControllerStyleAlert)) { + title = @""; + } + self = [[self class] alertControllerWithTitle:title message:message preferredStyle:preferredStyle]; + if (!self) return nil; + + self.jxt_setAlertAnimated = NO; + self.toastStyleDuration = JXTAlertShowDurationDefault; + + return self; +} + +- (void)alertAnimateDisabled +{ + self.jxt_setAlertAnimated = YES; +} + +- (JXTAlertActionTitle)addActionDefaultTitle +{ + //该block返回值不是本类属性,只是局部变量,不会造成循环引用 + return ^(NSString *title) { + JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init]; + actionModel.title = title; + actionModel.style = UIAlertActionStyleDefault; + [self.jxt_alertActionArray addObject:actionModel]; + return self; + }; +} + +- (JXTAlertActionTitle)addActionCancelTitle +{ + return ^(NSString *title) { + JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init]; + actionModel.title = title; + actionModel.style = UIAlertActionStyleCancel; + [self.jxt_alertActionArray addObject:actionModel]; + return self; + }; +} + +- (JXTAlertActionTitle)addActionDestructiveTitle +{ + return ^(NSString *title) { + JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init]; + actionModel.title = title; + actionModel.style = UIAlertActionStyleDestructive; + [self.jxt_alertActionArray addObject:actionModel]; + return self; + }; +} + +@end + + + +#pragma mark - III.UIViewController扩展 +@implementation UIViewController (JXTAlertController) + +- (void)jxt_showAlertWithPreferredStyle:(UIAlertControllerStyle)preferredStyle title:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock +{ + if (appearanceProcess) + { + JXTAlertController *alertMaker = [[JXTAlertController alloc] initAlertControllerWithTitle:title message:message preferredStyle:preferredStyle]; + //防止nil + if (!alertMaker) { + return ; + } + //加工链 + appearanceProcess(alertMaker); + //配置响应 + alertMaker.alertActionsConfig(actionBlock); +// alertMaker.alertActionsConfig(^(NSInteger buttonIndex, UIAlertAction *action){ +// if (actionBlock) { +// actionBlock(buttonIndex, action); +// } +// }); + + if (alertMaker.alertDidShown) + { + [self presentViewController:alertMaker animated:!(alertMaker.jxt_setAlertAnimated) completion:^{ + alertMaker.alertDidShown(); + }]; + } + else + { + [self presentViewController:alertMaker animated:!(alertMaker.jxt_setAlertAnimated) completion:NULL]; + } + } +} + +- (void)jxt_showAlertWithTitle:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock +{ + [self jxt_showAlertWithPreferredStyle:UIAlertControllerStyleAlert title:title message:message appearanceProcess:appearanceProcess actionsBlock:actionBlock]; +} + +- (void)jxt_showActionSheetWithTitle:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock +{ + [self jxt_showAlertWithPreferredStyle:UIAlertControllerStyleActionSheet title:title message:message appearanceProcess:appearanceProcess actionsBlock:actionBlock]; +} + +@end + diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.pbxproj b/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.pbxproj new file mode 100644 index 0000000..c6963da --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.pbxproj @@ -0,0 +1,341 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + A7AE30E920DCDCFA006C690F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A7AE30E820DCDCFA006C690F /* Assets.xcassets */; }; + A7AE30EC20DCDCFA006C690F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A7AE30EA20DCDCFA006C690F /* LaunchScreen.storyboard */; }; + A7AE30EF20DCDCFA006C690F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A7AE30EE20DCDCFA006C690F /* main.m */; }; + A7AE30FD20DCDD42006C690F /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A7AE30FA20DCDD42006C690F /* DemoViewController.m */; }; + A7AE30FE20DCDD42006C690F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A7AE30FC20DCDD42006C690F /* AppDelegate.m */; }; + A7AE310220DCDE00006C690F /* JXTAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = A7AE310120DCDE00006C690F /* JXTAlertController.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + A7AE30DC20DCDCF9006C690F /* JXTAlertControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JXTAlertControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + A7AE30E820DCDCFA006C690F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + A7AE30EB20DCDCFA006C690F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + A7AE30ED20DCDCFA006C690F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A7AE30EE20DCDCFA006C690F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + A7AE30F920DCDD42006C690F /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + A7AE30FA20DCDD42006C690F /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = ""; }; + A7AE30FB20DCDD42006C690F /* DemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoViewController.h; sourceTree = ""; }; + A7AE30FC20DCDD42006C690F /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + A7AE310020DCDE00006C690F /* JXTAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertController.h; sourceTree = ""; }; + A7AE310120DCDE00006C690F /* JXTAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JXTAlertController.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + A7AE30D920DCDCF9006C690F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + A7AE30D320DCDCF9006C690F = { + isa = PBXGroup; + children = ( + A7AE30FF20DCDE00006C690F /* JXTAlertController */, + A7AE30DE20DCDCF9006C690F /* JXTAlertControllerDemo */, + A7AE30DD20DCDCF9006C690F /* Products */, + ); + sourceTree = ""; + }; + A7AE30DD20DCDCF9006C690F /* Products */ = { + isa = PBXGroup; + children = ( + A7AE30DC20DCDCF9006C690F /* JXTAlertControllerDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + A7AE30DE20DCDCF9006C690F /* JXTAlertControllerDemo */ = { + isa = PBXGroup; + children = ( + A7AE30F920DCDD42006C690F /* AppDelegate.h */, + A7AE30FC20DCDD42006C690F /* AppDelegate.m */, + A7AE30FB20DCDD42006C690F /* DemoViewController.h */, + A7AE30FA20DCDD42006C690F /* DemoViewController.m */, + A7AE30E820DCDCFA006C690F /* Assets.xcassets */, + A7AE30EA20DCDCFA006C690F /* LaunchScreen.storyboard */, + A7AE30ED20DCDCFA006C690F /* Info.plist */, + A7AE30EE20DCDCFA006C690F /* main.m */, + ); + path = JXTAlertControllerDemo; + sourceTree = ""; + }; + A7AE30FF20DCDE00006C690F /* JXTAlertController */ = { + isa = PBXGroup; + children = ( + A7AE310020DCDE00006C690F /* JXTAlertController.h */, + A7AE310120DCDE00006C690F /* JXTAlertController.m */, + ); + name = JXTAlertController; + path = ../JXTAlertController; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + A7AE30DB20DCDCF9006C690F /* JXTAlertControllerDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = A7AE30F220DCDCFA006C690F /* Build configuration list for PBXNativeTarget "JXTAlertControllerDemo" */; + buildPhases = ( + A7AE30D820DCDCF9006C690F /* Sources */, + A7AE30D920DCDCF9006C690F /* Frameworks */, + A7AE30DA20DCDCF9006C690F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = JXTAlertControllerDemo; + productName = JXTAlertControllerDemo; + productReference = A7AE30DC20DCDCF9006C690F /* JXTAlertControllerDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + A7AE30D420DCDCF9006C690F /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0940; + ORGANIZATIONNAME = JXT; + TargetAttributes = { + A7AE30DB20DCDCF9006C690F = { + CreatedOnToolsVersion = 9.4.1; + }; + }; + }; + buildConfigurationList = A7AE30D720DCDCF9006C690F /* Build configuration list for PBXProject "JXTAlertControllerDemo" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = A7AE30D320DCDCF9006C690F; + productRefGroup = A7AE30DD20DCDCF9006C690F /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + A7AE30DB20DCDCF9006C690F /* JXTAlertControllerDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + A7AE30DA20DCDCF9006C690F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A7AE30EC20DCDCFA006C690F /* LaunchScreen.storyboard in Resources */, + A7AE30E920DCDCFA006C690F /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + A7AE30D820DCDCF9006C690F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A7AE30FE20DCDD42006C690F /* AppDelegate.m in Sources */, + A7AE310220DCDE00006C690F /* JXTAlertController.m in Sources */, + A7AE30FD20DCDD42006C690F /* DemoViewController.m in Sources */, + A7AE30EF20DCDCFA006C690F /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + A7AE30EA20DCDCFA006C690F /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + A7AE30EB20DCDCFA006C690F /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + A7AE30F020DCDCFA006C690F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + A7AE30F120DCDCFA006C690F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + A7AE30F320DCDCFA006C690F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = JXTAlertControllerDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.jxt.JXTAlertControllerDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + A7AE30F420DCDCFA006C690F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = JXTAlertControllerDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.jxt.JXTAlertControllerDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + A7AE30D720DCDCF9006C690F /* Build configuration list for PBXProject "JXTAlertControllerDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A7AE30F020DCDCFA006C690F /* Debug */, + A7AE30F120DCDCFA006C690F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + A7AE30F220DCDCFA006C690F /* Build configuration list for PBXNativeTarget "JXTAlertControllerDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A7AE30F320DCDCFA006C690F /* Debug */, + A7AE30F420DCDCFA006C690F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = A7AE30D420DCDCF9006C690F /* Project object */; +} diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..46ed90b --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.h b/JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.h new file mode 100644 index 0000000..c0eeee2 --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// JXTAlertControllerDemo +// +// Created by JXT on 2018/6/22. +// Copyright © 2018年 JXT. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.m b/JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.m new file mode 100644 index 0000000..1f15b1e --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/AppDelegate.m @@ -0,0 +1,57 @@ +// +// AppDelegate.m +// JXTAlertControllerDemo +// +// Created by JXT on 2018/6/22. +// Copyright © 2018年 JXT. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window.backgroundColor = [UIColor whiteColor]; + self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[NSClassFromString(@"DemoViewController") alloc] init]]; + + [self.window makeKeyAndVisible]; + + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // 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. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // 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. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // 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. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // 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. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/Contents.json b/JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/Base.lproj/LaunchScreen.storyboard b/JXTAlertControllerDemo/JXTAlertControllerDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..b993015 --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.h b/JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.h new file mode 100644 index 0000000..aff8d4b --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.h @@ -0,0 +1,13 @@ +// +// DemoViewController.h +// JXTAlertControllerDemo +// +// Created by JXT on 2018/6/22. +// Copyright © 2018年 JXT. All rights reserved. +// + +#import + +@interface DemoViewController : UIViewController + +@end diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.m b/JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.m new file mode 100644 index 0000000..e323bbe --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/DemoViewController.m @@ -0,0 +1,216 @@ +// +// DemoViewController.m +// JXTAlertControllerDemo +// +// Created by JXT on 2018/6/22. +// Copyright © 2018年 JXT. All rights reserved. +// + +#import "DemoViewController.h" + +#import "JXTAlertController.h" + +static NSString *const kDemoListCellId = @"DemoListCellId"; + +@interface DemoViewController () +@property (nonatomic, strong) UITableView * tableView; +@property (nonatomic, strong) NSArray * dataArray; + +@end + +@implementation DemoViewController + +#pragma mark - Life Cycle +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.navigationItem.title = @"JXTAlertManager"; + + self.dataArray = @[ + @"1.常规alertController-Alert", + @"2.常规alertController-ActionSheet", + @"3.无按钮alert-toast", + @"4.无按钮actionSheet-toast", + @"5.带输入框的alertController-Alert", + ]; + [self.view addSubview:self.tableView]; + + +#warning - 一种全局改变alert按钮titleColor的方式 +// [[UIView appearance] setTintColor:[UIColor grayColor]]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + +#pragma mark - Lazy Load +- (UITableView *)tableView +{ + if (!_tableView) { + _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; + _tableView.delegate = self; + _tableView.dataSource = self; + _tableView.backgroundColor = [UIColor whiteColor]; + _tableView.tableFooterView = [UIView new]; + + if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) { + self.automaticallyAdjustsScrollViewInsets = NO; + } + _tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0); + _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(64, 0, 0, 0); + + if (@available(iOS 11.0, *)) { + _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } else { + + } + } + return _tableView; +} + + +#pragma mark - UITableViewDataSource +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return self.dataArray.count; +} +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:kDemoListCellId]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kDemoListCellId]; + } + cell.backgroundColor = [self randomColor]; + cell.textLabel.text = self.dataArray[indexPath.row]; + cell.textLabel.numberOfLines = 0; + + return cell; +} + + +#pragma mark - UITableViewDelegate +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 70; +} + +#pragma mark alert使用示例 +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + 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 = 1; + [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 = 1; + //关闭动画效果 + [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 - Other 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 diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/Info.plist b/JXTAlertControllerDemo/JXTAlertControllerDemo/Info.plist new file mode 100644 index 0000000..20d26dc --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + JXTAlert + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + + + diff --git a/JXTAlertControllerDemo/JXTAlertControllerDemo/main.m b/JXTAlertControllerDemo/JXTAlertControllerDemo/main.m new file mode 100644 index 0000000..363b750 --- /dev/null +++ b/JXTAlertControllerDemo/JXTAlertControllerDemo/main.m @@ -0,0 +1,16 @@ +// +// main.m +// JXTAlertControllerDemo +// +// Created by JXT on 2018/6/22. +// Copyright © 2018年 JXT. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/JXTAlertManager.podspec b/JXTAlertManager.podspec new file mode 100644 index 0000000..e170fa5 --- /dev/null +++ b/JXTAlertManager.podspec @@ -0,0 +1,34 @@ +Pod::Spec.new do |s| + + # 简介 + s.name = 'JXTAlertController' + s.summary = 'A library easy to use UIAlertViewController on iOS.' + s.authors = { 'kukumaluCN' => '1145049339@qq.com' } + s.social_media_url = 'https://www.jianshu.com/u/c8f8558a4b1d' + + # 版本信息 + s.version = '1.0.0' + s.license = { :type => 'MIT', :file => 'LICENSE' } + + # 地址 + s.homepage = 'https://github.com/kukumaluCN/JXTAlertController' + s.source = { :git => 'https://github.com/kukumaluCN/JXTAlertController.git', :tag => s.version.to_s } + + # 系统 + s.requires_arc = true + s.platform = :ios, '8.0' + s.ios.deployment_target = '8.0' + + # 文件 + s.source_files = 'JXTAlertController/*.{h,m}' + # s.public_header_files = 'JXTAlertController/**/*.{h}' + # s.resources = "JXTAlertController/JXTAlertController/*.xcassets" + + + # 依赖 + # s.libraries = 'sqlite3' + # s.frameworks = 'UIKit', 'CoreFoundation', 'QuartzCore' + # s.dependency "JSONKit", "~> 1.4" + +end +