├── README.md
├── .DS_Store
├── DatePickerAlertView
├── Assets.xcassets
│ ├── Contents.json
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── ViewController.h
├── AppDelegate.h
├── main.m
├── DatePickerAlertView.h
├── Info.plist
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── ViewController.m
├── AppDelegate.m
└── DatePickerAlertView.m
└── DatePickerAlertView.xcodeproj
├── xcuserdata
└── psg_gui.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ └── xcschememanagement.plist
├── project.xcworkspace
├── contents.xcworkspacedata
├── xcuserdata
│ └── psg_gui.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcshareddata
│ └── IDEWorkspaceChecks.plist
└── project.pbxproj
/README.md:
--------------------------------------------------------------------------------
1 | # DatePickerAlertView
2 | DatePickerAlertView
3 |
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PSGGui/DatePickerAlertView/HEAD/.DS_Store
--------------------------------------------------------------------------------
/DatePickerAlertView/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/DatePickerAlertView.xcodeproj/xcuserdata/psg_gui.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/DatePickerAlertView.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DatePickerAlertView.xcodeproj/project.xcworkspace/xcuserdata/psg_gui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PSGGui/DatePickerAlertView/HEAD/DatePickerAlertView.xcodeproj/project.xcworkspace/xcuserdata/psg_gui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/DatePickerAlertView/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/DatePickerAlertView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/DatePickerAlertView/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. 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 |
--------------------------------------------------------------------------------
/DatePickerAlertView/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. 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 |
--------------------------------------------------------------------------------
/DatePickerAlertView.xcodeproj/xcuserdata/psg_gui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | DatePickerAlertView.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/DatePickerAlertView/DatePickerAlertView.h:
--------------------------------------------------------------------------------
1 | //
2 | // DatePickerAlertView.h
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #define D_yyyyMMddHHmmss @"yyyy-MM-dd HH:mm:ss" //时间标准模式——1.年-月-日 小时:分钟:秒钟
12 | #define D_yyyyMMddHHmm @"yyyy-MM-dd HH:mm" //时间标准模式——2.年-月-日 小时:分钟
13 | #define D_MMddHHmm @"MM-dd HH:mm" //时间标准模式-—3.月/日 小时:分钟
14 | #define D_yyyyMMdd @"yyyy年MM月dd日" //时间标准模式——4.年月日
15 | #define D_yyyy_MM_dd @"yyyy-MM-dd" //时间标准模式——5.年-月-日
16 | #define D_HHmm @"HH:mm" //时间标准模式——6.小时:分钟
17 |
18 | @interface DatePickerAlertView : UIView
19 |
20 | /**
21 | 显示时间选择器
22 |
23 | @param selectCompletion 完成回调
24 | */
25 | + (void)showDatePickerAlertViewWithSelectCompletion:(void (^)(NSDate *fromDate, NSDate *toDate))selectCompletion;
26 |
27 | /**
28 | 显示时间选择器(带时间格式,选择器类型)
29 |
30 | @param dateFormat 时间格式
31 | @param datePickerMode 选择器类型
32 | @param selectCompletion 完成回调
33 | */
34 | + (void)showDatePickerAlertViewWithDateFormat:(NSString *)dateFormat datePickerMode:(UIDatePickerMode)datePickerMode selectCompletion:(void (^)(NSDate *fromDate, NSDate *toDate))selectCompletion;
35 |
36 | /**
37 | 日期转换
38 |
39 | @param date 日期
40 | @param format 日期格式
41 | @return 日期字符串
42 | */
43 | + (NSString *)dateStringWithDate:(NSDate *)date format:(NSString *)format;
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/DatePickerAlertView/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
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 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/DatePickerAlertView/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 |
--------------------------------------------------------------------------------
/DatePickerAlertView/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "DatePickerAlertView.h"
11 |
12 | @interface ViewController ()
13 | @property (weak, nonatomic) IBOutlet UILabel *fromTimeLB;
14 | @property (weak, nonatomic) IBOutlet UILabel *toTimeLB;
15 |
16 | @end
17 |
18 | @implementation ViewController
19 |
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 | // Do any additional setup after loading the view, typically from a nib.
23 | }
24 |
25 |
26 | - (void)didReceiveMemoryWarning {
27 | [super didReceiveMemoryWarning];
28 | // Dispose of any resources that can be recreated.
29 | }
30 |
31 | - (IBAction)clicked:(UIButton *)sender {
32 | [DatePickerAlertView showDatePickerAlertViewWithDateFormat:sender.currentTitle
33 | datePickerMode:[@{D_yyyyMMddHHmmss : @(UIDatePickerModeDateAndTime),
34 | D_yyyy_MM_dd : @(UIDatePickerModeDate),
35 | D_HHmm : @(UIDatePickerModeTime)
36 | }[sender.currentTitle] integerValue]
37 | selectCompletion:^(NSDate *fromDate, NSDate *toDate) {
38 | self.fromTimeLB.text = [DatePickerAlertView dateStringWithDate:fromDate format:sender.currentTitle];
39 | self.toTimeLB.text = [DatePickerAlertView dateStringWithDate:toDate format:sender.currentTitle];
40 | }];
41 | // [DatePickerAlertView showDatePickerAlertViewWithSelectCompletion:^(NSDate *fromDate, NSDate *toDate) {
42 | // self.fromTimeLB.text = [DatePickerAlertView dateStringWithDate:fromDate format:D_yyyy_MM_dd];
43 | // self.toTimeLB.text = [DatePickerAlertView dateStringWithDate:toDate format:D_yyyy_MM_dd];
44 | // }];
45 | }
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/DatePickerAlertView/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/DatePickerAlertView/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. 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 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 |
24 | - (void)applicationWillResignActive:(UIApplication *)application {
25 | // 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.
26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
27 | }
28 |
29 |
30 | - (void)applicationDidEnterBackground:(UIApplication *)application {
31 | // 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.
32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
33 | }
34 |
35 |
36 | - (void)applicationWillEnterForeground:(UIApplication *)application {
37 | // 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.
38 | }
39 |
40 |
41 | - (void)applicationDidBecomeActive:(UIApplication *)application {
42 | // 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.
43 | }
44 |
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/DatePickerAlertView/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
30 |
37 |
44 |
53 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/DatePickerAlertView.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 90522B612136227D00CC061D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 90522B602136227D00CC061D /* AppDelegate.m */; };
11 | 90522B642136227D00CC061D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 90522B632136227D00CC061D /* ViewController.m */; };
12 | 90522B672136227D00CC061D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90522B652136227D00CC061D /* Main.storyboard */; };
13 | 90522B692136227F00CC061D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 90522B682136227F00CC061D /* Assets.xcassets */; };
14 | 90522B6C2136227F00CC061D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90522B6A2136227F00CC061D /* LaunchScreen.storyboard */; };
15 | 90522B6F2136227F00CC061D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 90522B6E2136227F00CC061D /* main.m */; };
16 | 90522B772136253300CC061D /* DatePickerAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 90522B762136253300CC061D /* DatePickerAlertView.m */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXFileReference section */
20 | 90522B5C2136227D00CC061D /* DatePickerAlertView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DatePickerAlertView.app; sourceTree = BUILT_PRODUCTS_DIR; };
21 | 90522B5F2136227D00CC061D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
22 | 90522B602136227D00CC061D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
23 | 90522B622136227D00CC061D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
24 | 90522B632136227D00CC061D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
25 | 90522B662136227D00CC061D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
26 | 90522B682136227F00CC061D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
27 | 90522B6B2136227F00CC061D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
28 | 90522B6D2136227F00CC061D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
29 | 90522B6E2136227F00CC061D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
30 | 90522B752136253300CC061D /* DatePickerAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DatePickerAlertView.h; sourceTree = ""; };
31 | 90522B762136253300CC061D /* DatePickerAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DatePickerAlertView.m; sourceTree = ""; };
32 | /* End PBXFileReference section */
33 |
34 | /* Begin PBXFrameworksBuildPhase section */
35 | 90522B592136227D00CC061D /* Frameworks */ = {
36 | isa = PBXFrameworksBuildPhase;
37 | buildActionMask = 2147483647;
38 | files = (
39 | );
40 | runOnlyForDeploymentPostprocessing = 0;
41 | };
42 | /* End PBXFrameworksBuildPhase section */
43 |
44 | /* Begin PBXGroup section */
45 | 90522B532136227D00CC061D = {
46 | isa = PBXGroup;
47 | children = (
48 | 90522B5E2136227D00CC061D /* DatePickerAlertView */,
49 | 90522B5D2136227D00CC061D /* Products */,
50 | );
51 | sourceTree = "";
52 | };
53 | 90522B5D2136227D00CC061D /* Products */ = {
54 | isa = PBXGroup;
55 | children = (
56 | 90522B5C2136227D00CC061D /* DatePickerAlertView.app */,
57 | );
58 | name = Products;
59 | sourceTree = "";
60 | };
61 | 90522B5E2136227D00CC061D /* DatePickerAlertView */ = {
62 | isa = PBXGroup;
63 | children = (
64 | 90522B5F2136227D00CC061D /* AppDelegate.h */,
65 | 90522B602136227D00CC061D /* AppDelegate.m */,
66 | 90522B622136227D00CC061D /* ViewController.h */,
67 | 90522B632136227D00CC061D /* ViewController.m */,
68 | 90522B652136227D00CC061D /* Main.storyboard */,
69 | 90522B682136227F00CC061D /* Assets.xcassets */,
70 | 90522B6A2136227F00CC061D /* LaunchScreen.storyboard */,
71 | 90522B6D2136227F00CC061D /* Info.plist */,
72 | 90522B6E2136227F00CC061D /* main.m */,
73 | 90522B752136253300CC061D /* DatePickerAlertView.h */,
74 | 90522B762136253300CC061D /* DatePickerAlertView.m */,
75 | );
76 | path = DatePickerAlertView;
77 | sourceTree = "";
78 | };
79 | /* End PBXGroup section */
80 |
81 | /* Begin PBXNativeTarget section */
82 | 90522B5B2136227D00CC061D /* DatePickerAlertView */ = {
83 | isa = PBXNativeTarget;
84 | buildConfigurationList = 90522B722136227F00CC061D /* Build configuration list for PBXNativeTarget "DatePickerAlertView" */;
85 | buildPhases = (
86 | 90522B582136227D00CC061D /* Sources */,
87 | 90522B592136227D00CC061D /* Frameworks */,
88 | 90522B5A2136227D00CC061D /* Resources */,
89 | );
90 | buildRules = (
91 | );
92 | dependencies = (
93 | );
94 | name = DatePickerAlertView;
95 | productName = DatePickerAlertView;
96 | productReference = 90522B5C2136227D00CC061D /* DatePickerAlertView.app */;
97 | productType = "com.apple.product-type.application";
98 | };
99 | /* End PBXNativeTarget section */
100 |
101 | /* Begin PBXProject section */
102 | 90522B542136227D00CC061D /* Project object */ = {
103 | isa = PBXProject;
104 | attributes = {
105 | LastUpgradeCheck = 0940;
106 | ORGANIZATIONNAME = G;
107 | TargetAttributes = {
108 | 90522B5B2136227D00CC061D = {
109 | CreatedOnToolsVersion = 9.4;
110 | };
111 | };
112 | };
113 | buildConfigurationList = 90522B572136227D00CC061D /* Build configuration list for PBXProject "DatePickerAlertView" */;
114 | compatibilityVersion = "Xcode 9.3";
115 | developmentRegion = en;
116 | hasScannedForEncodings = 0;
117 | knownRegions = (
118 | en,
119 | Base,
120 | );
121 | mainGroup = 90522B532136227D00CC061D;
122 | productRefGroup = 90522B5D2136227D00CC061D /* Products */;
123 | projectDirPath = "";
124 | projectRoot = "";
125 | targets = (
126 | 90522B5B2136227D00CC061D /* DatePickerAlertView */,
127 | );
128 | };
129 | /* End PBXProject section */
130 |
131 | /* Begin PBXResourcesBuildPhase section */
132 | 90522B5A2136227D00CC061D /* Resources */ = {
133 | isa = PBXResourcesBuildPhase;
134 | buildActionMask = 2147483647;
135 | files = (
136 | 90522B6C2136227F00CC061D /* LaunchScreen.storyboard in Resources */,
137 | 90522B692136227F00CC061D /* Assets.xcassets in Resources */,
138 | 90522B672136227D00CC061D /* Main.storyboard in Resources */,
139 | );
140 | runOnlyForDeploymentPostprocessing = 0;
141 | };
142 | /* End PBXResourcesBuildPhase section */
143 |
144 | /* Begin PBXSourcesBuildPhase section */
145 | 90522B582136227D00CC061D /* Sources */ = {
146 | isa = PBXSourcesBuildPhase;
147 | buildActionMask = 2147483647;
148 | files = (
149 | 90522B642136227D00CC061D /* ViewController.m in Sources */,
150 | 90522B6F2136227F00CC061D /* main.m in Sources */,
151 | 90522B612136227D00CC061D /* AppDelegate.m in Sources */,
152 | 90522B772136253300CC061D /* DatePickerAlertView.m in Sources */,
153 | );
154 | runOnlyForDeploymentPostprocessing = 0;
155 | };
156 | /* End PBXSourcesBuildPhase section */
157 |
158 | /* Begin PBXVariantGroup section */
159 | 90522B652136227D00CC061D /* Main.storyboard */ = {
160 | isa = PBXVariantGroup;
161 | children = (
162 | 90522B662136227D00CC061D /* Base */,
163 | );
164 | name = Main.storyboard;
165 | sourceTree = "";
166 | };
167 | 90522B6A2136227F00CC061D /* LaunchScreen.storyboard */ = {
168 | isa = PBXVariantGroup;
169 | children = (
170 | 90522B6B2136227F00CC061D /* Base */,
171 | );
172 | name = LaunchScreen.storyboard;
173 | sourceTree = "";
174 | };
175 | /* End PBXVariantGroup section */
176 |
177 | /* Begin XCBuildConfiguration section */
178 | 90522B702136227F00CC061D /* Debug */ = {
179 | isa = XCBuildConfiguration;
180 | buildSettings = {
181 | ALWAYS_SEARCH_USER_PATHS = NO;
182 | CLANG_ANALYZER_NONNULL = YES;
183 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
184 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
185 | CLANG_CXX_LIBRARY = "libc++";
186 | CLANG_ENABLE_MODULES = YES;
187 | CLANG_ENABLE_OBJC_ARC = YES;
188 | CLANG_ENABLE_OBJC_WEAK = YES;
189 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
190 | CLANG_WARN_BOOL_CONVERSION = YES;
191 | CLANG_WARN_COMMA = YES;
192 | CLANG_WARN_CONSTANT_CONVERSION = YES;
193 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
194 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
195 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
196 | CLANG_WARN_EMPTY_BODY = YES;
197 | CLANG_WARN_ENUM_CONVERSION = YES;
198 | CLANG_WARN_INFINITE_RECURSION = YES;
199 | CLANG_WARN_INT_CONVERSION = YES;
200 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
201 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
202 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
203 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
204 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
205 | CLANG_WARN_STRICT_PROTOTYPES = YES;
206 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
207 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
208 | CLANG_WARN_UNREACHABLE_CODE = YES;
209 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
210 | CODE_SIGN_IDENTITY = "iPhone Developer";
211 | COPY_PHASE_STRIP = NO;
212 | DEBUG_INFORMATION_FORMAT = dwarf;
213 | ENABLE_STRICT_OBJC_MSGSEND = YES;
214 | ENABLE_TESTABILITY = YES;
215 | GCC_C_LANGUAGE_STANDARD = gnu11;
216 | GCC_DYNAMIC_NO_PIC = NO;
217 | GCC_NO_COMMON_BLOCKS = YES;
218 | GCC_OPTIMIZATION_LEVEL = 0;
219 | GCC_PREPROCESSOR_DEFINITIONS = (
220 | "DEBUG=1",
221 | "$(inherited)",
222 | );
223 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
224 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
225 | GCC_WARN_UNDECLARED_SELECTOR = YES;
226 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
227 | GCC_WARN_UNUSED_FUNCTION = YES;
228 | GCC_WARN_UNUSED_VARIABLE = YES;
229 | IPHONEOS_DEPLOYMENT_TARGET = 11.4;
230 | MTL_ENABLE_DEBUG_INFO = YES;
231 | ONLY_ACTIVE_ARCH = YES;
232 | SDKROOT = iphoneos;
233 | };
234 | name = Debug;
235 | };
236 | 90522B712136227F00CC061D /* Release */ = {
237 | isa = XCBuildConfiguration;
238 | buildSettings = {
239 | ALWAYS_SEARCH_USER_PATHS = NO;
240 | CLANG_ANALYZER_NONNULL = YES;
241 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
242 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
243 | CLANG_CXX_LIBRARY = "libc++";
244 | CLANG_ENABLE_MODULES = YES;
245 | CLANG_ENABLE_OBJC_ARC = YES;
246 | CLANG_ENABLE_OBJC_WEAK = YES;
247 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
248 | CLANG_WARN_BOOL_CONVERSION = YES;
249 | CLANG_WARN_COMMA = YES;
250 | CLANG_WARN_CONSTANT_CONVERSION = YES;
251 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
253 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
254 | CLANG_WARN_EMPTY_BODY = YES;
255 | CLANG_WARN_ENUM_CONVERSION = YES;
256 | CLANG_WARN_INFINITE_RECURSION = YES;
257 | CLANG_WARN_INT_CONVERSION = YES;
258 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
259 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
260 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
261 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
262 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
263 | CLANG_WARN_STRICT_PROTOTYPES = YES;
264 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
265 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
266 | CLANG_WARN_UNREACHABLE_CODE = YES;
267 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
268 | CODE_SIGN_IDENTITY = "iPhone Developer";
269 | COPY_PHASE_STRIP = NO;
270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
271 | ENABLE_NS_ASSERTIONS = NO;
272 | ENABLE_STRICT_OBJC_MSGSEND = YES;
273 | GCC_C_LANGUAGE_STANDARD = gnu11;
274 | GCC_NO_COMMON_BLOCKS = YES;
275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
277 | GCC_WARN_UNDECLARED_SELECTOR = YES;
278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
279 | GCC_WARN_UNUSED_FUNCTION = YES;
280 | GCC_WARN_UNUSED_VARIABLE = YES;
281 | IPHONEOS_DEPLOYMENT_TARGET = 11.4;
282 | MTL_ENABLE_DEBUG_INFO = NO;
283 | SDKROOT = iphoneos;
284 | VALIDATE_PRODUCT = YES;
285 | };
286 | name = Release;
287 | };
288 | 90522B732136227F00CC061D /* Debug */ = {
289 | isa = XCBuildConfiguration;
290 | buildSettings = {
291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
292 | CODE_SIGN_STYLE = Automatic;
293 | DEVELOPMENT_TEAM = X3KF63X7J7;
294 | INFOPLIST_FILE = DatePickerAlertView/Info.plist;
295 | LD_RUNPATH_SEARCH_PATHS = (
296 | "$(inherited)",
297 | "@executable_path/Frameworks",
298 | );
299 | PRODUCT_BUNDLE_IDENTIFIER = cn.G.DatePickerAlertView;
300 | PRODUCT_NAME = "$(TARGET_NAME)";
301 | TARGETED_DEVICE_FAMILY = "1,2";
302 | };
303 | name = Debug;
304 | };
305 | 90522B742136227F00CC061D /* Release */ = {
306 | isa = XCBuildConfiguration;
307 | buildSettings = {
308 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
309 | CODE_SIGN_STYLE = Automatic;
310 | DEVELOPMENT_TEAM = X3KF63X7J7;
311 | INFOPLIST_FILE = DatePickerAlertView/Info.plist;
312 | LD_RUNPATH_SEARCH_PATHS = (
313 | "$(inherited)",
314 | "@executable_path/Frameworks",
315 | );
316 | PRODUCT_BUNDLE_IDENTIFIER = cn.G.DatePickerAlertView;
317 | PRODUCT_NAME = "$(TARGET_NAME)";
318 | TARGETED_DEVICE_FAMILY = "1,2";
319 | };
320 | name = Release;
321 | };
322 | /* End XCBuildConfiguration section */
323 |
324 | /* Begin XCConfigurationList section */
325 | 90522B572136227D00CC061D /* Build configuration list for PBXProject "DatePickerAlertView" */ = {
326 | isa = XCConfigurationList;
327 | buildConfigurations = (
328 | 90522B702136227F00CC061D /* Debug */,
329 | 90522B712136227F00CC061D /* Release */,
330 | );
331 | defaultConfigurationIsVisible = 0;
332 | defaultConfigurationName = Release;
333 | };
334 | 90522B722136227F00CC061D /* Build configuration list for PBXNativeTarget "DatePickerAlertView" */ = {
335 | isa = XCConfigurationList;
336 | buildConfigurations = (
337 | 90522B732136227F00CC061D /* Debug */,
338 | 90522B742136227F00CC061D /* Release */,
339 | );
340 | defaultConfigurationIsVisible = 0;
341 | defaultConfigurationName = Release;
342 | };
343 | /* End XCConfigurationList section */
344 | };
345 | rootObject = 90522B542136227D00CC061D /* Project object */;
346 | }
347 |
--------------------------------------------------------------------------------
/DatePickerAlertView/DatePickerAlertView.m:
--------------------------------------------------------------------------------
1 | //
2 | // DatePickerAlertView.m
3 | // DatePickerAlertView
4 | //
5 | // Created by SNICE on 2018/8/29.
6 | // Copyright © 2018年 G. All rights reserved.
7 | //
8 |
9 | #import "DatePickerAlertView.h"
10 |
11 | @implementation UIView (Frame)
12 |
13 | - (void)setPosition:(CGPoint)point atAnchorPoint:(CGPoint)anchorPoint
14 | {
15 | CGFloat x = point.x - anchorPoint.x * self.frame.size.width;
16 | CGFloat y = point.y - anchorPoint.y * self.frame.size.height;
17 | CGRect frame = self.frame;
18 | frame.origin = CGPointMake(x, y);
19 | self.frame = frame;
20 | }
21 |
22 | @end
23 |
24 | #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width //屏幕宽
25 | #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height //屏幕高
26 |
27 | #define ISIPHONEX \
28 | ^(){\
29 | BOOL iPhoneX = NO;\
30 | if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {\
31 | return iPhoneX;\
32 | }\
33 | if (@available(iOS 11.0, *)) {\
34 | UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];\
35 | if (mainWindow.safeAreaInsets.bottom > 0.0) {\
36 | iPhoneX = YES;\
37 | }\
38 | }\
39 | return iPhoneX;\
40 | }()
41 |
42 | #define STATUS_BAR_HEIGHT (ISIPHONEX ? 44.0f : 20.0f)
43 | #define NAVIGATION_BAR_HEIGHT (44.0f)
44 | #define STATUS_AND_NAVIGATION_BAR_HEIGHT ((STATUS_BAR_HEIGHT) + (NAVIGATION_BAR_HEIGHT))
45 | #define k_BOTTOM_SAFE_HEIGHT (CGFloat)(ISIPHONEX ? (34) : (0)) //iPhone X底部home键高度
46 |
47 | #define TIPS_ALERT_DURATION 0.25f //动画时长
48 | #define SHOW_DURATION 1.5f //显示时长
49 |
50 | @interface TipsAlertView : UIView
51 |
52 | @property (nonatomic, strong) NSString *tipsString;
53 | @property (nonatomic, strong, readonly) UILabel *tipsLabel;
54 |
55 | @end
56 |
57 | @implementation TipsAlertView
58 |
59 | + (void)showWithTips:(NSString *)tips {
60 | TipsAlertView *alertView = [[TipsAlertView alloc] init];
61 | alertView.tipsString = tips;
62 | [alertView setPosition:CGPointZero atAnchorPoint:CGPointMake(0, 1)];
63 | [[UIApplication sharedApplication].keyWindow addSubview:alertView];
64 | [alertView show];
65 | }
66 |
67 | - (instancetype)init
68 | {
69 | self = [super init];
70 | if (self) {
71 | self.backgroundColor = [UIColor whiteColor];
72 | self.frame = CGRectMake(0, 0, SCREEN_WIDTH, STATUS_AND_NAVIGATION_BAR_HEIGHT);
73 | self.clipsToBounds = YES;
74 |
75 | _tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 0, self.frame.size.width - 30.0f, self.frame.size.height)];
76 | _tipsLabel.font = [UIFont systemFontOfSize:15.0f];
77 | _tipsLabel.textColor = [UIColor redColor];
78 | _tipsLabel.textAlignment = NSTextAlignmentCenter;
79 | _tipsLabel.contentMode = UIViewContentModeBottom;
80 | _tipsLabel.numberOfLines = 0;
81 | _tipsLabel.lineBreakMode = NSLineBreakByCharWrapping;
82 | [self addSubview:_tipsLabel];
83 |
84 | UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
85 | tapGR.numberOfTapsRequired = 1;
86 | tapGR.numberOfTouchesRequired = 1;
87 | [self addGestureRecognizer:tapGR];
88 | }
89 | return self;
90 | }
91 |
92 | - (void)setTipsString:(NSString *)tipsString {
93 | _tipsString = tipsString;
94 | _tipsLabel.text = tipsString;
95 |
96 | [_tipsLabel sizeToFit];
97 | [_tipsLabel setPosition:CGPointMake(self.frame.size.width / 2, self.frame.size.height - 10.0f) atAnchorPoint:CGPointMake(0.5, 1)];
98 | }
99 |
100 | - (void)show {
101 | [UIView animateWithDuration:TIPS_ALERT_DURATION animations:^{
102 | [self setPosition:CGPointZero atAnchorPoint:CGPointZero];
103 | } completion:^(BOOL finished) {
104 | [self performSelector:@selector(hide) withObject:nil afterDelay:SHOW_DURATION];
105 | }];
106 | }
107 |
108 | - (void)hide {
109 | [NSObject cancelPreviousPerformRequestsWithTarget:self];
110 | [UIView animateWithDuration:TIPS_ALERT_DURATION animations:^{
111 | [self setPosition:CGPointZero atAnchorPoint:CGPointMake(0, 1)];
112 | } completion:^(BOOL finished) {
113 | [self removeFromSuperview];
114 | }];
115 | }
116 |
117 | @end
118 |
119 | #define HexColor(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0f green:((c>>8)&0xFF)/255.0f blue:(c&0xFF)/255.0f alpha:1.0f]
120 | #define TEXT_COLOR HexColor(0x111111) //文本默认显示颜色
121 | #define HIGHLIGHTED_COLOR HexColor(0x25c97c) //文本高亮显示颜色
122 | #define BACKGROUNG_COLOR HexColor(0xf5f7f9)
123 | #define TAG_COLOR HexColor(0x999999)
124 |
125 | #define ANIMATION_DURATION 0.5f //动画时长
126 | #define WINDOWVIEW_HEIGHT 300.0f //显示视图高度
127 | #define PICKERVIEW_HEIGHT 200.0f //时间选择器高度
128 | #define MARGIN 15.0f //边距
129 | #define LABEL_WIDTH 40.0f //"至"label宽度
130 | #define TEXTFIELD_WIDTH ((SCREEN_WIDTH - MARGIN * 2.0f - LABEL_WIDTH) / 2.0f) //textfield宽度
131 | #define TEXTFIELD_HEIGHT 30.0f //textfield高度
132 | #define BOTTOM_BUTTON_HEIGHT 40.0f //底部按钮高度
133 | #define BOTTOM_BUTTON_WIDTH (SCREEN_WIDTH / 2.0f) //底部按钮宽度
134 |
135 | #define FROM_TIME_BUTTON_PLACEHOLDER @"请选择开始时间"
136 | #define TO_TIME_BUTTON_PLACEHOLDER @"请选择结束时间"
137 | #define FROM_TIME_MORE_THEM_TO_TIME_TIPS @"开始时间不能大于结束时间"
138 | #define TO_TIME_LESS_THEM_FROM_TIME_TIPS @"结束时间不能小于开始时间"
139 | #define TO_TIME_IS_EMPTY_TIPS @"请选择结束时间"
140 |
141 | @interface DatePickerAlertView()
142 |
143 | @property (nonatomic, strong) UIWindow *window; //window
144 | @property (nonatomic, strong) UIView *blackMask; //黑色笼罩
145 | @property (nonatomic, strong) UIView *windowView; //显示view
146 |
147 | @property (nonatomic, strong) UIDatePicker *datePicker; //时间选择器
148 |
149 | @property (nonatomic, strong) UIButton *fromTimeButton; //开始时间按钮
150 | @property (nonatomic, strong) UIButton *toTimeButton; //结束时间按钮
151 |
152 | @property (nonatomic, strong) UIButton *resetButton; //重置按钮
153 | @property (nonatomic, strong) UIButton *ensureButton; //确定按钮
154 |
155 | @property (nonatomic, strong) NSString *dateFormat; //时间格式显示
156 | @property (nonatomic, assign) UIDatePickerMode datePickerMode; //日期控件显示类型
157 |
158 | @property (nonatomic, strong) NSDate *fromDate; //开始时间
159 | @property (nonatomic, strong) NSDate *toDate; //结束时间
160 |
161 | @property (nonatomic, strong) void (^didSelectDate)(NSDate *fromDate, NSDate *toDate);
162 |
163 | @end
164 |
165 | @implementation DatePickerAlertView
166 |
167 | + (void)showDatePickerAlertViewWithSelectCompletion:(void (^)(NSDate *fromDate, NSDate *toDate))selectCompletion {
168 | [self showDatePickerAlertViewWithDateFormat:D_yyyy_MM_dd datePickerMode:UIDatePickerModeDate selectCompletion:selectCompletion];
169 | }
170 |
171 | + (void)showDatePickerAlertViewWithDateFormat:(NSString *)dateFormat datePickerMode:(UIDatePickerMode)datePickerMode selectCompletion:(void (^)(NSDate *fromDate, NSDate *toDate))selectCompletion {
172 | DatePickerAlertView *alertView = [[DatePickerAlertView alloc] init];
173 | alertView.didSelectDate = ^(NSDate *fromDate, NSDate *toDate) {
174 | if (selectCompletion) selectCompletion(fromDate, toDate);
175 | };
176 | alertView.dateFormat = dateFormat;
177 | alertView.datePickerMode = datePickerMode;
178 | [alertView resetAction];
179 | [alertView show];
180 | }
181 |
182 | - (instancetype)init
183 | {
184 | self = [super init];
185 | if (self) {
186 | self.frame = [UIScreen mainScreen].bounds;
187 | self.backgroundColor = [UIColor clearColor];
188 | self.clipsToBounds = YES;
189 |
190 | [self addSubview:self.blackMask];
191 |
192 | [self.windowView setPosition:CGPointMake(0, SCREEN_HEIGHT) atAnchorPoint:CGPointZero];
193 | [self addSubview:self.windowView];
194 |
195 | [self.fromTimeButton setPosition:CGPointMake(MARGIN, MARGIN) atAnchorPoint:CGPointZero];
196 | [self.windowView addSubview:self.fromTimeButton];
197 |
198 | [self.toTimeButton setPosition:CGPointMake(SCREEN_WIDTH - MARGIN, MARGIN) atAnchorPoint:CGPointMake(1, 0)];
199 | [self.windowView addSubview:self.toTimeButton];
200 |
201 | [self.datePicker setPosition:CGPointMake(0, CGRectGetMaxY(self.fromTimeButton.frame) + MARGIN) atAnchorPoint:CGPointZero];
202 | [self.windowView addSubview:self.datePicker];
203 |
204 | [self.resetButton setPosition:CGPointMake(0, WINDOWVIEW_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
205 | [self.windowView addSubview:self.resetButton];
206 |
207 | [self.ensureButton setPosition:CGPointMake(SCREEN_WIDTH, WINDOWVIEW_HEIGHT) atAnchorPoint:CGPointMake(1, 1)];
208 | [self.windowView addSubview:self.ensureButton];
209 |
210 | UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
211 | tapGR.numberOfTapsRequired = 1;
212 | tapGR.numberOfTouchesRequired = 1;
213 | [self addGestureRecognizer:tapGR];
214 |
215 | _dateFormat = D_yyyy_MM_dd;
216 |
217 | [self resetAction];
218 | }
219 | return self;
220 | }
221 |
222 | - (void)resetAction {
223 | self.fromDate = [NSDate date];
224 | [self.datePicker setDate:self.fromDate animated:YES];
225 | self.fromTimeButton.selected = YES;
226 | [self.fromTimeButton setTitle:[self.class dateStringWithDate:_fromDate format:_dateFormat] forState:UIControlStateNormal];
227 |
228 | self.toDate = nil;
229 | self.toTimeButton.selected = NO;
230 | [self.toTimeButton setTitle:TO_TIME_BUTTON_PLACEHOLDER forState:UIControlStateNormal];
231 | }
232 |
233 | - (void)ensureAction {
234 | if (!self.toDate) {
235 | [TipsAlertView showWithTips:TO_TIME_IS_EMPTY_TIPS];
236 | return ;
237 | }
238 | if (self.didSelectDate) {
239 | self.didSelectDate(self.fromDate, self.toDate);
240 | }
241 | [self hide];
242 | }
243 |
244 | - (void)timeButtonAction {
245 | self.toTimeButton.selected = self.fromTimeButton.selected;
246 | self.fromTimeButton.selected = !self.fromTimeButton.selected;
247 | }
248 |
249 | - (void)dataPickerChanged:(UIDatePicker *)datePicker {
250 | NSString *dateString = [self.class dateStringWithDate:datePicker.date format:self.dateFormat];
251 | if (self.fromTimeButton.selected) {
252 | if ([self judgeDateIsErrorWithFromDate:datePicker.date toDate:self.toDate]) {
253 | [datePicker setDate:self.fromDate animated:YES];
254 | [TipsAlertView showWithTips:FROM_TIME_MORE_THEM_TO_TIME_TIPS];
255 | return ;
256 | }
257 | self.fromDate = datePicker.date;
258 | [self.fromTimeButton setTitle:dateString forState:UIControlStateNormal];
259 | } else {
260 | if ([self judgeDateIsErrorWithFromDate:self.fromDate toDate:datePicker.date]) {
261 | [datePicker setDate:self.toDate ? self.toDate : self.fromDate animated:YES];
262 | [TipsAlertView showWithTips:TO_TIME_LESS_THEM_FROM_TIME_TIPS];
263 | return ;
264 | }
265 | self.toDate = datePicker.date;
266 | [self.toTimeButton setTitle:dateString forState:UIControlStateNormal];
267 | }
268 | }
269 |
270 | + (NSString *)dateStringWithDate:(NSDate *)date format:(NSString *)format {
271 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
272 | formatter.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
273 | formatter.dateFormat = format;
274 | return [formatter stringFromDate:date];
275 | }
276 |
277 | - (BOOL)judgeDateIsErrorWithFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate {
278 | if (fromDate && toDate && fromDate.timeIntervalSinceReferenceDate >= toDate.timeIntervalSinceReferenceDate) return YES;
279 | return NO;
280 | }
281 |
282 | - (void)show {
283 | [self.window addSubview:self];
284 | [UIView animateWithDuration:ANIMATION_DURATION animations:^{
285 | self.blackMask.alpha = 0.2f;
286 | [self.windowView setPosition:CGPointMake(0, SCREEN_HEIGHT - k_BOTTOM_SAFE_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
287 | } completion:^(BOOL finished) {
288 | }];
289 | }
290 |
291 | - (void)hide {
292 | [UIView animateWithDuration:ANIMATION_DURATION animations:^{
293 | self.blackMask.alpha = 0.0f;
294 | [self.windowView setPosition:CGPointMake(0, SCREEN_HEIGHT) atAnchorPoint:CGPointMake(0, 0)];
295 | } completion:^(BOOL finished) {
296 | [self removeFromSuperview];
297 | }];
298 | }
299 |
300 | #pragma mark - setter method
301 |
302 | - (void)setDatePickerMode:(UIDatePickerMode)datePickerMode {
303 | _datePickerMode = datePickerMode;
304 | self.datePicker.datePickerMode = datePickerMode;
305 | }
306 |
307 | #pragma mark - Lazy loading
308 |
309 | - (UIWindow *)window {
310 | if (!_window) {
311 | _window = [UIApplication sharedApplication].keyWindow;
312 | }
313 | return _window;
314 | }
315 |
316 | - (UIView *)blackMask {
317 | if (!_blackMask) {
318 | _blackMask = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
319 | _blackMask.clipsToBounds = YES;
320 | _blackMask.alpha = 0.0f;
321 | _blackMask.backgroundColor = [UIColor blackColor];
322 | }
323 | return _blackMask;
324 | }
325 |
326 | - (UIView *)windowView {
327 | if (!_windowView) {
328 | _windowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, WINDOWVIEW_HEIGHT)];
329 | _windowView.backgroundColor = [UIColor whiteColor];
330 | _windowView.clipsToBounds = YES;
331 | }
332 | return _windowView;
333 | }
334 |
335 | - (UIButton *)fromTimeButton {
336 | if (!_fromTimeButton) {
337 | _fromTimeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT)];
338 | [_fromTimeButton setTitle:FROM_TIME_BUTTON_PLACEHOLDER forState:UIControlStateNormal];
339 | [_fromTimeButton setTitleColor:TAG_COLOR forState:UIControlStateNormal];
340 | [_fromTimeButton setTitleColor:HIGHLIGHTED_COLOR forState:UIControlStateSelected];
341 | _fromTimeButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
342 | [_fromTimeButton addTarget:self action:@selector(timeButtonAction) forControlEvents:UIControlEventTouchUpInside];
343 |
344 | UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, 1.0f)];
345 | lineView.backgroundColor = [UIColor blackColor];
346 | [lineView setPosition:CGPointMake(0, TEXTFIELD_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
347 | [_fromTimeButton addSubview:lineView];
348 | }
349 | return _fromTimeButton;
350 | }
351 |
352 | - (UIButton *)toTimeButton {
353 | if (!_toTimeButton) {
354 | _toTimeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT)];
355 | [_toTimeButton setTitle:TO_TIME_BUTTON_PLACEHOLDER forState:UIControlStateNormal];
356 | [_toTimeButton setTitleColor:TAG_COLOR forState:UIControlStateNormal];
357 | [_toTimeButton setTitleColor:HIGHLIGHTED_COLOR forState:UIControlStateSelected];
358 | _toTimeButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
359 | [_toTimeButton addTarget:self action:@selector(timeButtonAction) forControlEvents:UIControlEventTouchUpInside];
360 |
361 | UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, 1.0f)];
362 | lineView.backgroundColor = [UIColor blackColor];
363 | [lineView setPosition:CGPointMake(0, TEXTFIELD_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
364 | [_toTimeButton addSubview:lineView];
365 | }
366 | return _toTimeButton;
367 | }
368 |
369 | - (UIDatePicker *)datePicker {
370 | if (!_datePicker) {
371 | //创建一个UIPickView对象
372 | _datePicker = [[UIDatePicker alloc] init];
373 | _datePicker.frame = CGRectMake(0, 0, SCREEN_WIDTH, PICKERVIEW_HEIGHT);
374 | //设置背景颜色
375 | _datePicker.backgroundColor = [UIColor whiteColor];
376 | //设置本地化支持的语言(在此是中文)
377 | _datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
378 | //显示方式是只显示年月日
379 | _datePicker.datePickerMode = UIDatePickerModeDate;
380 | //监听变化
381 | [_datePicker addTarget:self action:@selector(dataPickerChanged:) forControlEvents:UIControlEventValueChanged];
382 | }
383 | return _datePicker;
384 | }
385 |
386 | - (UIButton *)resetButton {
387 | if (!_resetButton) {
388 | _resetButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_HEIGHT)];
389 | [_resetButton setTitle:@"重置" forState:UIControlStateNormal];
390 | [_resetButton setTitleColor:TEXT_COLOR forState:UIControlStateNormal];
391 | _resetButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
392 | _resetButton.backgroundColor = BACKGROUNG_COLOR;
393 |
394 | [_resetButton addTarget:self action:@selector(resetAction) forControlEvents:UIControlEventTouchUpInside];
395 | }
396 | return _resetButton;
397 | }
398 |
399 | - (UIButton *)ensureButton {
400 | if (!_ensureButton) {
401 | _ensureButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_HEIGHT)];
402 | [_ensureButton setTitle:@"确定" forState:UIControlStateNormal];
403 | [_ensureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
404 | _ensureButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
405 | _ensureButton.backgroundColor = HIGHLIGHTED_COLOR;
406 |
407 | [_ensureButton addTarget:self action:@selector(ensureAction) forControlEvents:UIControlEventTouchUpInside];
408 | }
409 | return _ensureButton;
410 | }
411 |
412 | @end
413 |
--------------------------------------------------------------------------------