├── screen.gif
├── HcdDateTimePickerDemo.xcodeproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcuserdata
│ │ ├── Jvaeyhcd.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ │ ├── salvador.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ │ └── polesapp-hcd.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
├── xcuserdata
│ ├── salvador.xcuserdatad
│ │ └── xcschemes
│ │ │ └── xcschememanagement.plist
│ ├── Jvaeyhcd.xcuserdatad
│ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ └── HcdDateTimePickerDemo.xcscheme
│ └── polesapp-hcd.xcuserdatad
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── HcdDateTimePickerDemo.xcscheme
└── project.pbxproj
├── HcdDateTimePickerDemo
├── ViewController.h
├── AppDelegate.h
├── main.m
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Info.plist
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
├── AppDelegate.m
└── ViewController.m
├── HcdDateTimePicker
├── UIColor+HcdCustom.h
├── MXSCycleScrollView.h
├── HcdDateTimePickerView.h
├── UIColor+HcdCustom.m
├── MXSCycleScrollView.m
└── HcdDateTimePickerView.m
├── LICENSE
├── README.md
└── HcdDateTimePicker.podspec
/screen.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jvaeyhcd/HcdDateTimePicker/HEAD/screen.gif
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcuserdata/Jvaeyhcd.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jvaeyhcd/HcdDateTimePicker/HEAD/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcuserdata/Jvaeyhcd.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcuserdata/salvador.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jvaeyhcd/HcdDateTimePicker/HEAD/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcuserdata/salvador.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcuserdata/polesapp-hcd.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jvaeyhcd/HcdDateTimePicker/HEAD/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcuserdata/polesapp-hcd.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // HcdDateTimePickerDemo
4 | //
5 | // Created by polesapp-hcd on 16/8/10.
6 | // Copyright © 2016年 Polesapp. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // HcdDateTimePickerDemo
4 | //
5 | // Created by polesapp-hcd on 16/8/10.
6 | // Copyright © 2016年 Polesapp. 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 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // HcdDateTimePickerDemo
4 | //
5 | // Created by polesapp-hcd on 16/8/10.
6 | // Copyright © 2016年 Polesapp. 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 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/xcuserdata/salvador.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HcdDateTimePickerDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 | HcdDateTimePickerDemo.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 0
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/xcuserdata/Jvaeyhcd.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HcdDateTimePickerDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 0CF8AA041D5AFD7A005F198A
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/xcuserdata/polesapp-hcd.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HcdDateTimePickerDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 0CF8AA041D5AFD7A005F198A
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/HcdDateTimePicker/UIColor+HcdCustom.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Jvaeyhcd on 15/10/21.
3 | //
4 | //
5 |
6 | #import
7 |
8 | @interface UIColor (HcdCustom)
9 |
10 | @property (nonatomic, readonly) CGColorSpaceModel colorSpaceModel;
11 | @property (nonatomic, readonly) BOOL canProvideRGBComponents;
12 | @property (nonatomic, readonly) CGFloat red; // Only valid if canProvideRGBComponents is YES
13 | @property (nonatomic, readonly) CGFloat green; // Only valid if canProvideRGBComponents is YES
14 | @property (nonatomic, readonly) CGFloat blue; // Only valid if canProvideRGBComponents is YES
15 | @property (nonatomic, readonly) CGFloat white; // Only valid if colorSpaceModel == kCGColorSpaceModelMonochrome
16 | @property (nonatomic, readonly) CGFloat alpha;
17 | @property (nonatomic, readonly) UInt32 rgbHex;
18 |
19 | + (UIColor *)colorWithRGBHex:(UInt32)hex;
20 | + (UIColor *)colorWithHexString:(NSString *)stringToConvert;
21 | + (UIColor *)colorWithHexString:(NSString *)stringToConvert andAlpha:(CGFloat)alpha;
22 | @end
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | copyright (c) 2013-2016 HcdCachePlayer (https://github.com/Jvaeyhcd/HcdCachePlayer)
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
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 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/HcdDateTimePicker/MXSCycleScrollView.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Jvaeyhcd on 15/10/21.
3 | //
4 | //
5 |
6 |
7 | #import
8 |
9 | @protocol MXSCycleScrollViewDelegate;
10 | @protocol MXSCycleScrollViewDatasource;
11 |
12 | @interface MXSCycleScrollView : UIView
13 | {
14 | UIScrollView *_scrollView;
15 |
16 | NSInteger _totalPages;
17 | NSInteger _curPage;
18 |
19 | NSMutableArray *_curViews;
20 | }
21 |
22 | @property (nonatomic,readonly) UIScrollView *scrollView;
23 | @property (nonatomic,assign) NSInteger currentPage;
24 | @property (nonatomic,assign,setter = setDataource:) id datasource;
25 | @property (nonatomic,assign,setter = setDelegate:) id delegate;
26 |
27 | - (void)setCurrentSelectPage:(NSInteger)selectPage; //设置初始化页数
28 | - (void)reloadData;
29 | - (void)setViewContent:(UIView *)view atIndex:(NSInteger)index;
30 |
31 | @end
32 |
33 | @protocol MXSCycleScrollViewDelegate
34 |
35 | @optional
36 | - (void)didClickPage:(MXSCycleScrollView *)csView atIndex:(NSInteger)index;
37 | - (void)scrollviewDidChangeNumber;
38 |
39 | @end
40 |
41 | @protocol MXSCycleScrollViewDatasource
42 |
43 | @required
44 | - (NSInteger)numberOfPages:(MXSCycleScrollView*)scrollView;
45 | - (UIView *)pageAtIndex:(NSInteger)index andScrollView:(MXSCycleScrollView*)scrollView;
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/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 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/HcdDateTimePicker/HcdDateTimePickerView.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Jvaeyhcd on 15/10/21.
3 | //
4 | //
5 |
6 | #define kScreen_Height [UIScreen mainScreen].bounds.size.height
7 | #define kScreen_Width [UIScreen mainScreen].bounds.size.width
8 |
9 | #define kScaleFrom_iPhone5_Desgin(_X_) floor(_X_ * (kScreen_Width/320))
10 |
11 | #import
12 | #import "MXSCycleScrollView.h"
13 |
14 | typedef enum {
15 | DatePickerDateMode,
16 | DatePickerTimeMode,
17 | DatePickerDateTimeMode,
18 | DatePickerYearMonthMode,
19 | DatePickerMonthDayMode,
20 | DatePickerHourMinuteMode,
21 | DatePickerDateHourMinuteMode
22 | } DatePickerMode;
23 |
24 | typedef void(^DatePickerCompleteAnimationBlock)(BOOL Complete);
25 | typedef void(^ClickedOkBtn)(NSString *dateTimeStr);
26 |
27 | @interface HcdDateTimePickerView : UIView
28 | @property (nonatomic,copy ) ClickedOkBtn clickedOkBtn;
29 |
30 | @property (nonatomic,assign) DatePickerMode datePickerMode;
31 |
32 | @property (nonatomic,assign) NSInteger maxYear;
33 | @property (nonatomic,assign) NSInteger minYear;
34 |
35 | @property (nonatomic,strong) UIColor *topViewColor;
36 | @property (nonatomic,strong) UIColor *buttonTitleColor;
37 |
38 | /// 顶部文字颜色
39 | @property (nonatomic,strong) UIColor *titleColor;
40 |
41 | /// 顶部文字
42 | @property (nonatomic,copy ) NSString *title;
43 |
44 | /// 取消文字
45 | @property (nonatomic, copy) NSString *cancleText;
46 |
47 | /// 取消文字颜色
48 | @property (nonatomic, strong) UIColor *cancleColor;
49 |
50 | /// 确定文字
51 | @property (nonatomic, copy) NSString *okText;
52 |
53 | /// 确定文字颜色
54 | @property (nonatomic, strong) UIColor *okColor;
55 |
56 | -(instancetype)initWithDefaultDatetime:(NSDate*)dateTime;
57 | -(instancetype)initWithDatePickerMode:(DatePickerMode)datePickerMode defaultDateTime:(NSDate*)dateTime;
58 | -(void) showHcdDateTimePicker;
59 | @end
60 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // HcdDateTimePickerDemo
4 | //
5 | // Created by polesapp-hcd on 16/8/10.
6 | // Copyright © 2016年 Polesapp. 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 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // 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.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // 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.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // 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.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HcdDateTimePicker
2 | [](http://cocoapods.org/pods/HcdDateTimePicker)
3 | [](http://cocoapods.org/pods/HcdDateTimePicker)
4 | [](http://cocoapods.org/pods/HcdDateTimePicker)
5 | [](http://cocoapods.org/pods/HcdDateTimePicker)
7 | [](http://www.jvaeyhcd.cc)
8 |
9 | A beautiful DateTimePicker.
10 |
11 | 
12 |
13 | ## Requirements
14 | * Xcode 6 or higher
15 | * iOS 7.0 or higher
16 | * ARC
17 |
18 | ## Installation
19 |
20 | ### Manual Install
21 | All you need to do is drop `HCDDateTimePicker` files into your project, and add #include `HCDDateTimePicker.h` to the top of classes that will use it.
22 |
23 | ### Cocoapods
24 | Change to the directory of your Xcode project:
25 | ```
26 | $ cd /path/to/YourProject
27 | $ touch Podfile
28 | $ edit Podfile
29 | ```
30 | Edit your project's `Podfile` and add the following:
31 | ```
32 | pod 'HcdDateTimePicker'
33 | ```
34 | Install into your Xcode project:
35 | ```
36 | pod setup
37 | pod install
38 | ```
39 |
40 | ## Example
41 | ```
42 | HcdDateTimePickerView *dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerDateMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:0]];
43 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
44 | NSLog(@"%@", datetimeStr);
45 | };
46 | [self.view addSubview:dateTimePickerView];
47 | [dateTimePickerView showHcdDateTimePicker];
48 | ```
49 |
50 | ## TODO
51 | * [x] DatePickerDateMode
52 | * [x] DatePickerTimeMode
53 | * [x] DatePickerDateTimeMode
54 | * [x] DatePickerYearMonthMode
55 | * [x] DatePickerMonthDayMode
56 | * [x] DatePickerHourMinuteMode
57 | * [x] DatePickerDateHourMinuteMode
58 |
59 | ## Contact me
60 | If you find some bugs or you have some suggest, please contact me or [post me an issue](https://github.com/Jvaeyhcd/HcdDateTimePicker/issues/new).Thank you!
61 | * Email: chedahuang@icloud.com
62 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/xcuserdata/Jvaeyhcd.xcuserdatad/xcschemes/HcdDateTimePickerDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/xcuserdata/polesapp-hcd.xcuserdatad/xcschemes/HcdDateTimePickerDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/HcdDateTimePicker/UIColor+HcdCustom.m:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Jvaeyhcd on 15/10/21.
3 | //
4 | //
5 |
6 | #import "UIColor+HcdCustom.h"
7 |
8 | @implementation UIColor (HcdCustom)
9 |
10 | - (CGColorSpaceModel)colorSpaceModel {
11 | return CGColorSpaceGetModel(CGColorGetColorSpace(self.CGColor));
12 | }
13 |
14 | - (BOOL)canProvideRGBComponents {
15 | switch (self.colorSpaceModel) {
16 | case kCGColorSpaceModelRGB:
17 | case kCGColorSpaceModelMonochrome:
18 | return YES;
19 | default:
20 | return NO;
21 | }
22 | }
23 |
24 | - (CGFloat)red {
25 | NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -red");
26 | const CGFloat *c = CGColorGetComponents(self.CGColor);
27 | return c[0];
28 | }
29 |
30 | - (CGFloat)green {
31 | NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -green");
32 | const CGFloat *c = CGColorGetComponents(self.CGColor);
33 | if (self.colorSpaceModel == kCGColorSpaceModelMonochrome) return c[0];
34 | return c[1];
35 | }
36 |
37 | - (CGFloat)blue {
38 | NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -blue");
39 | const CGFloat *c = CGColorGetComponents(self.CGColor);
40 | if (self.colorSpaceModel == kCGColorSpaceModelMonochrome) return c[0];
41 | return c[2];
42 | }
43 |
44 | - (CGFloat)white {
45 | NSAssert(self.colorSpaceModel == kCGColorSpaceModelMonochrome, @"Must be a Monochrome color to use -white");
46 | const CGFloat *c = CGColorGetComponents(self.CGColor);
47 | return c[0];
48 | }
49 |
50 | - (CGFloat)alpha {
51 | return CGColorGetAlpha(self.CGColor);
52 | }
53 |
54 | - (UInt32)rgbHex {
55 | NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use rgbHex");
56 |
57 | CGFloat r,g,b,a;
58 | if (![self red:&r green:&g blue:&b alpha:&a]) return 0;
59 |
60 | r = MIN(MAX(self.red, 0.0f), 1.0f);
61 | g = MIN(MAX(self.green, 0.0f), 1.0f);
62 | b = MIN(MAX(self.blue, 0.0f), 1.0f);
63 |
64 | return (((int)roundf(r * 255)) << 16)
65 | | (((int)roundf(g * 255)) << 8)
66 | | (((int)roundf(b * 255)));
67 | }
68 |
69 | - (BOOL)red:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha {
70 | const CGFloat *components = CGColorGetComponents(self.CGColor);
71 |
72 | CGFloat r,g,b,a;
73 |
74 | switch (self.colorSpaceModel) {
75 | case kCGColorSpaceModelMonochrome:
76 | r = g = b = components[0];
77 | a = components[1];
78 | break;
79 | case kCGColorSpaceModelRGB:
80 | r = components[0];
81 | g = components[1];
82 | b = components[2];
83 | a = components[3];
84 | break;
85 | default: // We don't know how to handle this model
86 | return NO;
87 | }
88 |
89 | if (red) *red = r;
90 | if (green) *green = g;
91 | if (blue) *blue = b;
92 | if (alpha) *alpha = a;
93 |
94 | return YES;
95 | }
96 |
97 |
98 | + (UIColor *)colorWithRGBHex:(UInt32)hex {
99 | int r = (hex >> 16) & 0xFF;
100 | int g = (hex >> 8) & 0xFF;
101 | int b = (hex) & 0xFF;
102 |
103 | return [UIColor colorWithRed:r / 255.0f
104 | green:g / 255.0f
105 | blue:b / 255.0f
106 | alpha:1.0f];
107 | }
108 |
109 | + (UIColor *)colorWithHexString:(NSString *)stringToConvert {
110 | NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
111 | unsigned hexNum;
112 | if (![scanner scanHexInt:&hexNum]) return nil;
113 | return [UIColor colorWithRGBHex:hexNum];
114 | }
115 | + (UIColor *)colorWithHexString:(NSString *)stringToConvert andAlpha:(CGFloat)alpha{
116 | UIColor *color = [UIColor colorWithHexString:stringToConvert];
117 | return [UIColor colorWithRed:color.red green:color.green blue:color.blue alpha:alpha];
118 | }
119 | @end
120 |
--------------------------------------------------------------------------------
/HcdDateTimePicker.podspec:
--------------------------------------------------------------------------------
1 | #
2 | # Be sure to run `pod spec lint HcdDateTimePicker.podspec' to ensure this is a
3 | # valid spec and to remove all comments including this before submitting the spec.
4 | #
5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7 | #
8 |
9 | Pod::Spec.new do |s|
10 |
11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12 | #
13 | # These will help people to find your library, and whilst it
14 | # can feel like a chore to fill in it's definitely to your advantage. The
15 | # summary should be tweet-length, and the description more in depth.
16 | #
17 |
18 | s.name = "HcdDateTimePicker"
19 | s.version = "1.1.3"
20 | s.summary = "A beautiful DateTimePicker."
21 |
22 | # This description is used to generate tags and improve search results.
23 | # * Think: What does it do? Why did you write it? What is the focus?
24 | # * Try to keep it short, snappy and to the point.
25 | # * Write the description between the DESC delimiters below.
26 | # * Finally, don't worry about the indent, CocoaPods strips it!
27 | s.description = <<-DESC
28 | 一个自定义从底部弹出的时间选择器,支持多种样式的时间选择
29 | DESC
30 |
31 | s.homepage = "https://github.com/Jvaeyhcd/HcdDateTimePicker"
32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
33 |
34 |
35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
36 | #
37 | # Licensing your code is important. See http://choosealicense.com for more info.
38 | # CocoaPods will detect a license file if there is a named LICENSE*
39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
40 | #
41 |
42 | # s.license = "MIT (example)"
43 | s.license = { :type => "MIT", :file => "LICENSE" }
44 |
45 |
46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
47 | #
48 | # Specify the authors of the library, with email addresses. Email addresses
49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
50 | # accepts just a name if you'd rather not provide an email address.
51 | #
52 | # Specify a social_media_url where others can refer to, for example a twitter
53 | # profile URL.
54 | #
55 |
56 | s.author = { "Jvaeyhcd" => "chedahuang@icloud.com" }
57 | # Or just: s.author = "Jvaeyhcd"
58 | # s.authors = { "Jvaeyhcd" => "chedahuang@icloud.com" }
59 | # s.social_media_url = "http://twitter.com/Jvaeyhcd"
60 |
61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
62 | #
63 | # If this Pod runs only on iOS or OS X, then specify the platform and
64 | # the deployment target. You can optionally include the target after the platform.
65 | #
66 |
67 | # s.platform = :ios
68 | s.platform = :ios, "7.0"
69 |
70 | # When using multiple platforms
71 | # s.ios.deployment_target = "5.0"
72 | # s.osx.deployment_target = "10.7"
73 | # s.watchos.deployment_target = "2.0"
74 | # s.tvos.deployment_target = "9.0"
75 |
76 |
77 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
78 | #
79 | # Specify the location from where the source should be retrieved.
80 | # Supports git, hg, bzr, svn and HTTP.
81 | #
82 |
83 | s.source = { :git => "https://github.com/Jvaeyhcd/HcdDateTimePicker.git", :tag => s.version.to_s }
84 |
85 |
86 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
87 | #
88 | # CocoaPods is smart about how it includes source code. For source files
89 | # giving a folder will include any swift, h, m, mm, c & cpp files.
90 | # For header files it will include any header in the folder.
91 | # Not including the public_header_files will make all headers public.
92 | #
93 |
94 | s.source_files = "HcdDateTimePicker/**/*.{h,m}"
95 |
96 |
97 | # s.public_header_files = "Classes/**/*.h"
98 |
99 |
100 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
101 | #
102 | # A list of resources included with the Pod. These are copied into the
103 | # target bundle with a build phase script. Anything else will be cleaned.
104 | # You can preserve files from being cleaned, please don't preserve
105 | # non-essential files like tests, examples and documentation.
106 | #
107 |
108 | # s.resource = "icon.png"
109 | # s.resources = "Resources/*.png"
110 |
111 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
112 |
113 |
114 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
115 | #
116 | # Link your library with frameworks, or libraries. Libraries do not include
117 | # the lib prefix of their name.
118 | #
119 |
120 | # s.framework = "SomeFramework"
121 | # s.frameworks = "SomeFramework", "AnotherFramework"
122 |
123 | # s.library = "iconv"
124 | # s.libraries = "iconv", "xml2"
125 |
126 |
127 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
128 | #
129 | # If your library depends on compiler flags you can set them in the xcconfig hash
130 | # where they will only apply to your library. If you depend on other Podspecs
131 | # you can include multiple dependencies to ensure it works.
132 |
133 | s.requires_arc = true
134 |
135 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
136 | # s.dependency "JSONKit", "~> 1.4"
137 |
138 | end
139 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // HcdDateTimePickerDemo
4 | //
5 | // Created by polesapp-hcd on 16/8/10.
6 | // Copyright © 2016年 Polesapp. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "HcdDateTimePickerView.h"
11 |
12 | #define kBasePadding 15
13 | #define kScreenWidth [UIScreen mainScreen].bounds.size.width
14 | #define kScreenHeight [UIScreen mainScreen].bounds.size.height
15 |
16 | @interface ViewController (){
17 | HcdDateTimePickerView * dateTimePickerView;
18 | }
19 |
20 | @property (nonatomic, strong) UILabel *timeLbl;
21 |
22 | @end
23 |
24 | @implementation ViewController
25 |
26 | - (void)viewDidLoad {
27 | [super viewDidLoad];
28 | // Do any additional setup after loading the view, typically from a nib.
29 |
30 | self.timeLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, kScreenWidth, 20)];
31 | self.timeLbl.textAlignment = NSTextAlignmentCenter;
32 | self.timeLbl.font = [UIFont systemFontOfSize:14];
33 | [self.view addSubview:self.timeLbl];
34 |
35 | UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, 100, kScreenWidth - 2*kBasePadding, 40)];
36 | btn1.layer.cornerRadius = 4;
37 | btn1.backgroundColor = [UIColor grayColor];
38 | [btn1 setTitle:@"YYYY-MM-DD HH:mm:ss" forState:UIControlStateNormal];
39 | btn1.tag = 1;
40 | [btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
41 | [self.view addSubview:btn1];
42 |
43 | UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, CGRectGetMaxY(btn1.frame) + kBasePadding, kScreenWidth - 2*kBasePadding, 40)];
44 | btn2.layer.cornerRadius = 4;
45 | btn2.backgroundColor = [UIColor grayColor];
46 | [btn2 setTitle:@"YYYY-MM-DD" forState:UIControlStateNormal];
47 | btn2.tag = 2;
48 | [btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
49 | [self.view addSubview:btn2];
50 |
51 | UIButton *btn3 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, CGRectGetMaxY(btn2.frame) + kBasePadding, kScreenWidth - 2*kBasePadding, 40)];
52 | btn3.layer.cornerRadius = 4;
53 | btn3.backgroundColor = [UIColor grayColor];
54 | [btn3 setTitle:@"HH:mm:ss" forState:UIControlStateNormal];
55 | btn3.tag = 3;
56 | [btn3 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
57 | [self.view addSubview:btn3];
58 |
59 | UIButton *btn4 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, CGRectGetMaxY(btn3.frame) + kBasePadding, kScreenWidth - 2*kBasePadding, 40)];
60 | btn4.layer.cornerRadius = 4;
61 | btn4.backgroundColor = [UIColor grayColor];
62 | [btn4 setTitle:@"YYYY-MM" forState:UIControlStateNormal];
63 | btn4.tag = 4;
64 | [btn4 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
65 | [self.view addSubview:btn4];
66 |
67 | UIButton *btn5 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, CGRectGetMaxY(btn4.frame) + kBasePadding, kScreenWidth - 2*kBasePadding, 40)];
68 | btn5.layer.cornerRadius = 4;
69 | btn5.backgroundColor = [UIColor grayColor];
70 | [btn5 setTitle:@"MM-DD" forState:UIControlStateNormal];
71 | btn5.tag = 5;
72 | [btn5 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
73 | [self.view addSubview:btn5];
74 |
75 | UIButton *btn6 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, CGRectGetMaxY(btn5.frame) + kBasePadding, kScreenWidth - 2*kBasePadding, 40)];
76 | btn6.layer.cornerRadius = 4;
77 | btn6.backgroundColor = [UIColor grayColor];
78 | [btn6 setTitle:@"HH:mm" forState:UIControlStateNormal];
79 | btn6.tag = 6;
80 | [btn6 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
81 | [self.view addSubview:btn6];
82 |
83 | UIButton *btn7 = [[UIButton alloc]initWithFrame:CGRectMake(kBasePadding, CGRectGetMaxY(btn6.frame) + kBasePadding, kScreenWidth - 2*kBasePadding, 40)];
84 | btn7.layer.cornerRadius = 4;
85 | btn7.backgroundColor = [UIColor grayColor];
86 | [btn7 setTitle:@"YYYY-MM-DD HH:mm" forState:UIControlStateNormal];
87 | btn7.tag = 7;
88 | [btn7 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
89 | [self.view addSubview:btn7];
90 |
91 | }
92 |
93 | - (void)btnClicked:(UIButton *)btn {
94 | NSInteger tag = btn.tag;
95 |
96 | __block ViewController *weakSelf = self;
97 |
98 | switch (tag) {
99 | case 1:
100 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerDateTimeMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
101 | dateTimePickerView.topViewColor = [UIColor greenColor];
102 | dateTimePickerView.buttonTitleColor = [UIColor redColor];
103 | [dateTimePickerView setMinYear:1990];
104 | [dateTimePickerView setMaxYear:2016];
105 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
106 | NSLog(@"%@", datetimeStr);
107 | weakSelf.timeLbl.text = datetimeStr;
108 | };
109 | break;
110 | case 2:
111 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerDateMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
112 | [dateTimePickerView setMinYear:1990];
113 | [dateTimePickerView setMaxYear:2016];
114 |
115 | dateTimePickerView.title = @"出生日期";
116 | dateTimePickerView.titleColor = [UIColor yellowColor];
117 |
118 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
119 | NSLog(@"%@", datetimeStr);
120 | weakSelf.timeLbl.text = datetimeStr;
121 | };
122 | break;
123 | case 3:
124 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerTimeMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
125 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
126 | NSLog(@"%@", datetimeStr);
127 | weakSelf.timeLbl.text = datetimeStr;
128 | };
129 | break;
130 | case 4:
131 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerYearMonthMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
132 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
133 | NSLog(@"%@", datetimeStr);
134 | weakSelf.timeLbl.text = datetimeStr;
135 | };
136 | break;
137 | case 5:
138 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerMonthDayMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
139 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
140 | NSLog(@"%@", datetimeStr);
141 | weakSelf.timeLbl.text = datetimeStr;
142 | };
143 | break;
144 | case 6:
145 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerHourMinuteMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
146 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
147 | NSLog(@"%@", datetimeStr);
148 | weakSelf.timeLbl.text = datetimeStr;
149 | };
150 | break;
151 | case 7:
152 | dateTimePickerView = [[HcdDateTimePickerView alloc] initWithDatePickerMode:DatePickerDateHourMinuteMode defaultDateTime:[[NSDate alloc]initWithTimeIntervalSinceNow:1000]];
153 | dateTimePickerView.clickedOkBtn = ^(NSString * datetimeStr){
154 | NSLog(@"%@", datetimeStr);
155 | weakSelf.timeLbl.text = datetimeStr;
156 | };
157 | break;
158 | default:
159 | break;
160 | }
161 |
162 | if (dateTimePickerView) {
163 | [self.view addSubview:dateTimePickerView];
164 | [dateTimePickerView showHcdDateTimePicker];
165 | }
166 | }
167 |
168 | - (void)didReceiveMemoryWarning {
169 | [super didReceiveMemoryWarning];
170 | // Dispose of any resources that can be recreated.
171 | }
172 |
173 | @end
174 |
--------------------------------------------------------------------------------
/HcdDateTimePicker/MXSCycleScrollView.m:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Jvaeyhcd on 15/10/21.
3 | //
4 | //
5 |
6 | #import "MXSCycleScrollView.h"
7 | #import "UIColor+HcdCustom.h"
8 |
9 | @implementation MXSCycleScrollView
10 |
11 | @synthesize scrollView = _scrollView;
12 | @synthesize currentPage = _curPage;
13 | @synthesize datasource = _datasource;
14 | @synthesize delegate = _delegate;
15 |
16 | - (id)initWithFrame:(CGRect)frame
17 | {
18 | self = [super initWithFrame:frame];
19 | if (self) {
20 | // Initialization code
21 | _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
22 | _scrollView.delegate = self;
23 | _scrollView.contentSize = CGSizeMake(self.bounds.size.width, (self.bounds.size.height/5)*7);
24 | _scrollView.showsHorizontalScrollIndicator = NO;
25 | _scrollView.showsVerticalScrollIndicator = NO;
26 | _scrollView.contentOffset = CGPointMake(0, (self.bounds.size.height/5));
27 |
28 | [self addSubview:_scrollView];
29 | }
30 | return self;
31 | }
32 | //设置初始化页数
33 | - (void)setCurrentSelectPage:(NSInteger)selectPage
34 | {
35 | _curPage = selectPage;
36 | }
37 |
38 | - (void)setDataource:(id)datasource
39 | {
40 | _datasource = datasource;
41 | [self reloadData];
42 | }
43 |
44 | - (void)reloadData
45 | {
46 | _totalPages = [_datasource numberOfPages:self];
47 | if (_totalPages == 0) {
48 | return;
49 | }
50 | [self loadData];
51 | }
52 |
53 | - (void)loadData
54 | {
55 | //从scrollView上移除所有的subview
56 | NSArray *subViews = [_scrollView subviews];
57 | if([subViews count] != 0) {
58 | [subViews makeObjectsPerformSelector:@selector(removeFromSuperview)];
59 | }
60 |
61 | [self getDisplayImagesWithCurpage:_curPage];
62 |
63 | for (int i = 0; i < 7; i++) {
64 | UIView *v = [_curViews objectAtIndex:i];
65 | // v.userInteractionEnabled = YES;
66 | // UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self
67 | // action:@selector(handleTap:)];
68 | // [v addGestureRecognizer:singleTap];
69 | v.frame = CGRectOffset(v.frame, 0, v.frame.size.height * i );
70 | [_scrollView addSubview:v];
71 | }
72 |
73 | [_scrollView setContentOffset:CGPointMake( 0, (self.bounds.size.height/5) )];
74 | }
75 |
76 | - (void)getDisplayImagesWithCurpage:(NSInteger)page {
77 | NSInteger pre1 = [self validPageValue:_curPage-1];
78 | NSInteger pre2 = [self validPageValue:_curPage];
79 | NSInteger pre3 = [self validPageValue:_curPage+1];
80 | NSInteger pre4 = [self validPageValue:_curPage+2];
81 | NSInteger pre5 = [self validPageValue:_curPage+3];
82 | NSInteger pre = [self validPageValue:_curPage+4];
83 | NSInteger last = [self validPageValue:_curPage+5];
84 |
85 | if (!_curViews) {
86 | _curViews = [[NSMutableArray alloc] init];
87 | }
88 |
89 | [_curViews removeAllObjects];
90 |
91 | [_curViews addObject:[_datasource pageAtIndex:pre1 andScrollView:self]];
92 | [_curViews addObject:[_datasource pageAtIndex:pre2 andScrollView:self]];
93 | [_curViews addObject:[_datasource pageAtIndex:pre3 andScrollView:self]];
94 | [_curViews addObject:[_datasource pageAtIndex:pre4 andScrollView:self]];
95 | [_curViews addObject:[_datasource pageAtIndex:pre5 andScrollView:self]];
96 | [_curViews addObject:[_datasource pageAtIndex:pre andScrollView:self]];
97 | [_curViews addObject:[_datasource pageAtIndex:last andScrollView:self]];
98 | }
99 |
100 | - (NSInteger)validPageValue:(NSInteger)value {
101 |
102 | if(value < 0 ) value = _totalPages + value;
103 | if(value == _totalPages+1) value = 1;
104 | if (value == _totalPages+2) value = 2;
105 | if(value == _totalPages+3) value = 3;
106 | if (value == _totalPages+4) value = 4;
107 | if(value == _totalPages) value = 0;
108 |
109 |
110 | return value;
111 |
112 | }
113 |
114 | - (void)handleTap:(UITapGestureRecognizer *)tap {
115 |
116 | if ([_delegate respondsToSelector:@selector(didClickPage:atIndex:)]) {
117 | [_delegate didClickPage:self atIndex:_curPage];
118 | }
119 |
120 | }
121 |
122 | - (void)setViewContent:(UIView *)view atIndex:(NSInteger)index
123 | {
124 | if (index == _curPage) {
125 | [_curViews replaceObjectAtIndex:1 withObject:view];
126 | for (int i = 0; i < 7; i++) {
127 | UIView *v = [_curViews objectAtIndex:i];
128 | v.userInteractionEnabled = YES;
129 | // UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self
130 | // action:@selector(handleTap:)];
131 | // [v addGestureRecognizer:singleTap];
132 | v.frame = CGRectOffset(v.frame, 0, v.frame.size.height * i);
133 | [_scrollView addSubview:v];
134 | }
135 | }
136 | }
137 |
138 | - (void)setAfterScrollShowView:(UIScrollView*)scrollview andCurrentPage:(NSInteger)pageNumber
139 | {
140 | UILabel *oneLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber];
141 | [oneLabel setFont:[UIFont systemFontOfSize:14]];
142 | [oneLabel setTextColor:[UIColor colorWithHexString:@"0xBABABA"]];
143 | UILabel *twoLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+1];
144 | [twoLabel setFont:[UIFont systemFontOfSize:16]];
145 | [twoLabel setTextColor:[UIColor colorWithHexString:@"0x717171"]];
146 |
147 | UILabel *currentLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+2];
148 | [currentLabel setFont:[UIFont systemFontOfSize:18]];
149 | [currentLabel setTextColor:[UIColor blackColor]];
150 |
151 | UILabel *threeLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+3];
152 | [threeLabel setFont:[UIFont systemFontOfSize:16]];
153 | [threeLabel setTextColor:[UIColor colorWithHexString:@"0x717171"]];
154 | UILabel *fourLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+4];
155 | [fourLabel setFont:[UIFont systemFontOfSize:14]];
156 | [fourLabel setTextColor:[UIColor colorWithHexString:@"0xBABABA"]];
157 | }
158 |
159 | #pragma mark - UIScrollViewDelegate
160 | - (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
161 | int y = aScrollView.contentOffset.y;
162 | NSInteger page = aScrollView.contentOffset.y/((self.bounds.size.height/5));
163 |
164 | if (y>2*(self.bounds.size.height/5)) {
165 | _curPage = [self validPageValue:_curPage+1];
166 | [self loadData];
167 | }
168 | if (y<=0) {
169 | _curPage = [self validPageValue:_curPage-1];
170 | [self loadData];
171 | }
172 | // //往下翻一张
173 | // if(x >= (4*self.frame.size.width)) {
174 | // _curPage = [self validPageValue:_curPage+1];
175 | // [self loadData];
176 | // }
177 | //
178 | // //往上翻
179 | // if(x <= 0) {
180 | //
181 | // }
182 | if (page>1 || page <=0) {
183 | [self setAfterScrollShowView:aScrollView andCurrentPage:1];
184 | }
185 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) {
186 | [_delegate scrollviewDidChangeNumber];
187 | }
188 | }
189 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
190 | {
191 | [self setAfterScrollShowView:scrollView andCurrentPage:1];
192 | }
193 |
194 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
195 | {
196 | [_scrollView setContentOffset:CGPointMake(0, (self.bounds.size.height/5)) animated:YES];
197 | [self setAfterScrollShowView:scrollView andCurrentPage:1];
198 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) {
199 | [_delegate scrollviewDidChangeNumber];
200 | }
201 | }
202 |
203 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
204 | {
205 | [self setAfterScrollShowView:scrollView andCurrentPage:1];
206 | }
207 |
208 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
209 | [_scrollView setContentOffset:CGPointMake(0, (self.bounds.size.height/5)) animated:YES];
210 | [self setAfterScrollShowView:scrollView andCurrentPage:1];
211 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) {
212 | [_delegate scrollviewDidChangeNumber];
213 | }
214 | }
215 |
216 | @end
217 |
--------------------------------------------------------------------------------
/HcdDateTimePickerDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 0CF8AA0A1D5AFD7A005F198A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF8AA091D5AFD7A005F198A /* main.m */; };
11 | 0CF8AA0D1D5AFD7A005F198A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF8AA0C1D5AFD7A005F198A /* AppDelegate.m */; };
12 | 0CF8AA101D5AFD7A005F198A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF8AA0F1D5AFD7A005F198A /* ViewController.m */; };
13 | 0CF8AA131D5AFD7A005F198A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0CF8AA111D5AFD7A005F198A /* Main.storyboard */; };
14 | 0CF8AA151D5AFD7A005F198A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0CF8AA141D5AFD7A005F198A /* Assets.xcassets */; };
15 | 0CF8AA181D5AFD7A005F198A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0CF8AA161D5AFD7A005F198A /* LaunchScreen.storyboard */; };
16 | 0CF8AA261D5AFDD2005F198A /* HcdDateTimePickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF8AA211D5AFDD2005F198A /* HcdDateTimePickerView.m */; };
17 | 0CF8AA271D5AFDD2005F198A /* MXSCycleScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF8AA231D5AFDD2005F198A /* MXSCycleScrollView.m */; };
18 | 0CF8AA281D5AFDD2005F198A /* UIColor+HcdCustom.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF8AA251D5AFDD2005F198A /* UIColor+HcdCustom.m */; };
19 | /* End PBXBuildFile section */
20 |
21 | /* Begin PBXFileReference section */
22 | 0CF8AA051D5AFD7A005F198A /* HcdDateTimePickerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HcdDateTimePickerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
23 | 0CF8AA091D5AFD7A005F198A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
24 | 0CF8AA0B1D5AFD7A005F198A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
25 | 0CF8AA0C1D5AFD7A005F198A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
26 | 0CF8AA0E1D5AFD7A005F198A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
27 | 0CF8AA0F1D5AFD7A005F198A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
28 | 0CF8AA121D5AFD7A005F198A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
29 | 0CF8AA141D5AFD7A005F198A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
30 | 0CF8AA171D5AFD7A005F198A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
31 | 0CF8AA191D5AFD7A005F198A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
32 | 0CF8AA201D5AFDD2005F198A /* HcdDateTimePickerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HcdDateTimePickerView.h; sourceTree = ""; };
33 | 0CF8AA211D5AFDD2005F198A /* HcdDateTimePickerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HcdDateTimePickerView.m; sourceTree = ""; };
34 | 0CF8AA221D5AFDD2005F198A /* MXSCycleScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXSCycleScrollView.h; sourceTree = ""; };
35 | 0CF8AA231D5AFDD2005F198A /* MXSCycleScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXSCycleScrollView.m; sourceTree = ""; };
36 | 0CF8AA241D5AFDD2005F198A /* UIColor+HcdCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+HcdCustom.h"; sourceTree = ""; };
37 | 0CF8AA251D5AFDD2005F198A /* UIColor+HcdCustom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+HcdCustom.m"; sourceTree = ""; };
38 | /* End PBXFileReference section */
39 |
40 | /* Begin PBXFrameworksBuildPhase section */
41 | 0CF8AA021D5AFD7A005F198A /* Frameworks */ = {
42 | isa = PBXFrameworksBuildPhase;
43 | buildActionMask = 2147483647;
44 | files = (
45 | );
46 | runOnlyForDeploymentPostprocessing = 0;
47 | };
48 | /* End PBXFrameworksBuildPhase section */
49 |
50 | /* Begin PBXGroup section */
51 | 0CF8A9FC1D5AFD7A005F198A = {
52 | isa = PBXGroup;
53 | children = (
54 | 0CF8AA1F1D5AFDD2005F198A /* HcdDateTimePicker */,
55 | 0CF8AA071D5AFD7A005F198A /* HcdDateTimePickerDemo */,
56 | 0CF8AA061D5AFD7A005F198A /* Products */,
57 | );
58 | sourceTree = "";
59 | };
60 | 0CF8AA061D5AFD7A005F198A /* Products */ = {
61 | isa = PBXGroup;
62 | children = (
63 | 0CF8AA051D5AFD7A005F198A /* HcdDateTimePickerDemo.app */,
64 | );
65 | name = Products;
66 | sourceTree = "";
67 | };
68 | 0CF8AA071D5AFD7A005F198A /* HcdDateTimePickerDemo */ = {
69 | isa = PBXGroup;
70 | children = (
71 | 0CF8AA0B1D5AFD7A005F198A /* AppDelegate.h */,
72 | 0CF8AA0C1D5AFD7A005F198A /* AppDelegate.m */,
73 | 0CF8AA0E1D5AFD7A005F198A /* ViewController.h */,
74 | 0CF8AA0F1D5AFD7A005F198A /* ViewController.m */,
75 | 0CF8AA111D5AFD7A005F198A /* Main.storyboard */,
76 | 0CF8AA141D5AFD7A005F198A /* Assets.xcassets */,
77 | 0CF8AA161D5AFD7A005F198A /* LaunchScreen.storyboard */,
78 | 0CF8AA191D5AFD7A005F198A /* Info.plist */,
79 | 0CF8AA081D5AFD7A005F198A /* Supporting Files */,
80 | );
81 | path = HcdDateTimePickerDemo;
82 | sourceTree = "";
83 | };
84 | 0CF8AA081D5AFD7A005F198A /* Supporting Files */ = {
85 | isa = PBXGroup;
86 | children = (
87 | 0CF8AA091D5AFD7A005F198A /* main.m */,
88 | );
89 | name = "Supporting Files";
90 | sourceTree = "";
91 | };
92 | 0CF8AA1F1D5AFDD2005F198A /* HcdDateTimePicker */ = {
93 | isa = PBXGroup;
94 | children = (
95 | 0CF8AA201D5AFDD2005F198A /* HcdDateTimePickerView.h */,
96 | 0CF8AA211D5AFDD2005F198A /* HcdDateTimePickerView.m */,
97 | 0CF8AA221D5AFDD2005F198A /* MXSCycleScrollView.h */,
98 | 0CF8AA231D5AFDD2005F198A /* MXSCycleScrollView.m */,
99 | 0CF8AA241D5AFDD2005F198A /* UIColor+HcdCustom.h */,
100 | 0CF8AA251D5AFDD2005F198A /* UIColor+HcdCustom.m */,
101 | );
102 | name = HcdDateTimePicker;
103 | path = HCDDateTimePicker;
104 | sourceTree = SOURCE_ROOT;
105 | };
106 | /* End PBXGroup section */
107 |
108 | /* Begin PBXNativeTarget section */
109 | 0CF8AA041D5AFD7A005F198A /* HcdDateTimePickerDemo */ = {
110 | isa = PBXNativeTarget;
111 | buildConfigurationList = 0CF8AA1C1D5AFD7A005F198A /* Build configuration list for PBXNativeTarget "HcdDateTimePickerDemo" */;
112 | buildPhases = (
113 | 0CF8AA011D5AFD7A005F198A /* Sources */,
114 | 0CF8AA021D5AFD7A005F198A /* Frameworks */,
115 | 0CF8AA031D5AFD7A005F198A /* Resources */,
116 | );
117 | buildRules = (
118 | );
119 | dependencies = (
120 | );
121 | name = HcdDateTimePickerDemo;
122 | productName = HcdDateTimePickerDemo;
123 | productReference = 0CF8AA051D5AFD7A005F198A /* HcdDateTimePickerDemo.app */;
124 | productType = "com.apple.product-type.application";
125 | };
126 | /* End PBXNativeTarget section */
127 |
128 | /* Begin PBXProject section */
129 | 0CF8A9FD1D5AFD7A005F198A /* Project object */ = {
130 | isa = PBXProject;
131 | attributes = {
132 | LastUpgradeCheck = 0730;
133 | ORGANIZATIONNAME = Polesapp;
134 | TargetAttributes = {
135 | 0CF8AA041D5AFD7A005F198A = {
136 | CreatedOnToolsVersion = 7.3.1;
137 | DevelopmentTeam = NLP5PZS8U3;
138 | ProvisioningStyle = Automatic;
139 | };
140 | };
141 | };
142 | buildConfigurationList = 0CF8AA001D5AFD7A005F198A /* Build configuration list for PBXProject "HcdDateTimePickerDemo" */;
143 | compatibilityVersion = "Xcode 3.2";
144 | developmentRegion = English;
145 | hasScannedForEncodings = 0;
146 | knownRegions = (
147 | English,
148 | en,
149 | Base,
150 | );
151 | mainGroup = 0CF8A9FC1D5AFD7A005F198A;
152 | productRefGroup = 0CF8AA061D5AFD7A005F198A /* Products */;
153 | projectDirPath = "";
154 | projectRoot = "";
155 | targets = (
156 | 0CF8AA041D5AFD7A005F198A /* HcdDateTimePickerDemo */,
157 | );
158 | };
159 | /* End PBXProject section */
160 |
161 | /* Begin PBXResourcesBuildPhase section */
162 | 0CF8AA031D5AFD7A005F198A /* Resources */ = {
163 | isa = PBXResourcesBuildPhase;
164 | buildActionMask = 2147483647;
165 | files = (
166 | 0CF8AA181D5AFD7A005F198A /* LaunchScreen.storyboard in Resources */,
167 | 0CF8AA151D5AFD7A005F198A /* Assets.xcassets in Resources */,
168 | 0CF8AA131D5AFD7A005F198A /* Main.storyboard in Resources */,
169 | );
170 | runOnlyForDeploymentPostprocessing = 0;
171 | };
172 | /* End PBXResourcesBuildPhase section */
173 |
174 | /* Begin PBXSourcesBuildPhase section */
175 | 0CF8AA011D5AFD7A005F198A /* Sources */ = {
176 | isa = PBXSourcesBuildPhase;
177 | buildActionMask = 2147483647;
178 | files = (
179 | 0CF8AA101D5AFD7A005F198A /* ViewController.m in Sources */,
180 | 0CF8AA0D1D5AFD7A005F198A /* AppDelegate.m in Sources */,
181 | 0CF8AA281D5AFDD2005F198A /* UIColor+HcdCustom.m in Sources */,
182 | 0CF8AA0A1D5AFD7A005F198A /* main.m in Sources */,
183 | 0CF8AA261D5AFDD2005F198A /* HcdDateTimePickerView.m in Sources */,
184 | 0CF8AA271D5AFDD2005F198A /* MXSCycleScrollView.m in Sources */,
185 | );
186 | runOnlyForDeploymentPostprocessing = 0;
187 | };
188 | /* End PBXSourcesBuildPhase section */
189 |
190 | /* Begin PBXVariantGroup section */
191 | 0CF8AA111D5AFD7A005F198A /* Main.storyboard */ = {
192 | isa = PBXVariantGroup;
193 | children = (
194 | 0CF8AA121D5AFD7A005F198A /* Base */,
195 | );
196 | name = Main.storyboard;
197 | sourceTree = "";
198 | };
199 | 0CF8AA161D5AFD7A005F198A /* LaunchScreen.storyboard */ = {
200 | isa = PBXVariantGroup;
201 | children = (
202 | 0CF8AA171D5AFD7A005F198A /* Base */,
203 | );
204 | name = LaunchScreen.storyboard;
205 | sourceTree = "";
206 | };
207 | /* End PBXVariantGroup section */
208 |
209 | /* Begin XCBuildConfiguration section */
210 | 0CF8AA1A1D5AFD7A005F198A /* Debug */ = {
211 | isa = XCBuildConfiguration;
212 | buildSettings = {
213 | ALWAYS_SEARCH_USER_PATHS = NO;
214 | CLANG_ANALYZER_NONNULL = YES;
215 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
216 | CLANG_CXX_LIBRARY = "libc++";
217 | CLANG_ENABLE_MODULES = YES;
218 | CLANG_ENABLE_OBJC_ARC = YES;
219 | CLANG_WARN_BOOL_CONVERSION = YES;
220 | CLANG_WARN_CONSTANT_CONVERSION = YES;
221 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
222 | CLANG_WARN_EMPTY_BODY = YES;
223 | CLANG_WARN_ENUM_CONVERSION = YES;
224 | CLANG_WARN_INT_CONVERSION = YES;
225 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
226 | CLANG_WARN_UNREACHABLE_CODE = YES;
227 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
228 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
229 | COPY_PHASE_STRIP = NO;
230 | DEBUG_INFORMATION_FORMAT = dwarf;
231 | ENABLE_STRICT_OBJC_MSGSEND = YES;
232 | ENABLE_TESTABILITY = YES;
233 | GCC_C_LANGUAGE_STANDARD = gnu99;
234 | GCC_DYNAMIC_NO_PIC = NO;
235 | GCC_NO_COMMON_BLOCKS = YES;
236 | GCC_OPTIMIZATION_LEVEL = 0;
237 | GCC_PREPROCESSOR_DEFINITIONS = (
238 | "DEBUG=1",
239 | "$(inherited)",
240 | );
241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
243 | GCC_WARN_UNDECLARED_SELECTOR = YES;
244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
245 | GCC_WARN_UNUSED_FUNCTION = YES;
246 | GCC_WARN_UNUSED_VARIABLE = YES;
247 | IPHONEOS_DEPLOYMENT_TARGET = 9.3;
248 | MTL_ENABLE_DEBUG_INFO = YES;
249 | ONLY_ACTIVE_ARCH = YES;
250 | SDKROOT = iphoneos;
251 | };
252 | name = Debug;
253 | };
254 | 0CF8AA1B1D5AFD7A005F198A /* Release */ = {
255 | isa = XCBuildConfiguration;
256 | buildSettings = {
257 | ALWAYS_SEARCH_USER_PATHS = NO;
258 | CLANG_ANALYZER_NONNULL = YES;
259 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
260 | CLANG_CXX_LIBRARY = "libc++";
261 | CLANG_ENABLE_MODULES = YES;
262 | CLANG_ENABLE_OBJC_ARC = YES;
263 | CLANG_WARN_BOOL_CONVERSION = YES;
264 | CLANG_WARN_CONSTANT_CONVERSION = YES;
265 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
266 | CLANG_WARN_EMPTY_BODY = YES;
267 | CLANG_WARN_ENUM_CONVERSION = YES;
268 | CLANG_WARN_INT_CONVERSION = YES;
269 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
270 | CLANG_WARN_UNREACHABLE_CODE = YES;
271 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
272 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
273 | COPY_PHASE_STRIP = NO;
274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
275 | ENABLE_NS_ASSERTIONS = NO;
276 | ENABLE_STRICT_OBJC_MSGSEND = YES;
277 | GCC_C_LANGUAGE_STANDARD = gnu99;
278 | GCC_NO_COMMON_BLOCKS = YES;
279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
281 | GCC_WARN_UNDECLARED_SELECTOR = YES;
282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
283 | GCC_WARN_UNUSED_FUNCTION = YES;
284 | GCC_WARN_UNUSED_VARIABLE = YES;
285 | IPHONEOS_DEPLOYMENT_TARGET = 9.3;
286 | MTL_ENABLE_DEBUG_INFO = NO;
287 | SDKROOT = iphoneos;
288 | VALIDATE_PRODUCT = YES;
289 | };
290 | name = Release;
291 | };
292 | 0CF8AA1D1D5AFD7A005F198A /* Debug */ = {
293 | isa = XCBuildConfiguration;
294 | buildSettings = {
295 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
296 | CODE_SIGN_IDENTITY = "Apple Development";
297 | CODE_SIGN_STYLE = Automatic;
298 | DEVELOPMENT_TEAM = NLP5PZS8U3;
299 | INFOPLIST_FILE = HcdDateTimePickerDemo/Info.plist;
300 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
301 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
302 | PRODUCT_BUNDLE_IDENTIFIER = jvaeyhcd.cc.HcdDateTimePickerDemo;
303 | PRODUCT_NAME = "$(TARGET_NAME)";
304 | PROVISIONING_PROFILE_SPECIFIER = "";
305 | };
306 | name = Debug;
307 | };
308 | 0CF8AA1E1D5AFD7A005F198A /* Release */ = {
309 | isa = XCBuildConfiguration;
310 | buildSettings = {
311 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
312 | CODE_SIGN_IDENTITY = "Apple Development";
313 | CODE_SIGN_STYLE = Automatic;
314 | DEVELOPMENT_TEAM = NLP5PZS8U3;
315 | INFOPLIST_FILE = HcdDateTimePickerDemo/Info.plist;
316 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
317 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
318 | PRODUCT_BUNDLE_IDENTIFIER = jvaeyhcd.cc.HcdDateTimePickerDemo;
319 | PRODUCT_NAME = "$(TARGET_NAME)";
320 | PROVISIONING_PROFILE_SPECIFIER = "";
321 | };
322 | name = Release;
323 | };
324 | /* End XCBuildConfiguration section */
325 |
326 | /* Begin XCConfigurationList section */
327 | 0CF8AA001D5AFD7A005F198A /* Build configuration list for PBXProject "HcdDateTimePickerDemo" */ = {
328 | isa = XCConfigurationList;
329 | buildConfigurations = (
330 | 0CF8AA1A1D5AFD7A005F198A /* Debug */,
331 | 0CF8AA1B1D5AFD7A005F198A /* Release */,
332 | );
333 | defaultConfigurationIsVisible = 0;
334 | defaultConfigurationName = Release;
335 | };
336 | 0CF8AA1C1D5AFD7A005F198A /* Build configuration list for PBXNativeTarget "HcdDateTimePickerDemo" */ = {
337 | isa = XCConfigurationList;
338 | buildConfigurations = (
339 | 0CF8AA1D1D5AFD7A005F198A /* Debug */,
340 | 0CF8AA1E1D5AFD7A005F198A /* Release */,
341 | );
342 | defaultConfigurationIsVisible = 0;
343 | defaultConfigurationName = Release;
344 | };
345 | /* End XCConfigurationList section */
346 | };
347 | rootObject = 0CF8A9FD1D5AFD7A005F198A /* Project object */;
348 | }
349 |
--------------------------------------------------------------------------------
/HcdDateTimePicker/HcdDateTimePickerView.m:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Jvaeyhcd on 15/10/21.
3 | //
4 | //
5 |
6 | //屏幕的宽高
7 | #define isIPhopeX ((kScreen_Height == 812.f || kScreen_Width == 812.f || kScreen_Width == 896.f || kScreen_Height == 896.f) ? YES : NO)
8 |
9 | #define kSafeBottomMargin (isIPhopeX ? 34.f : 0.f)
10 |
11 | #define kTopViewHeight kScaleFrom_iPhone5_Desgin(44)
12 | #define kTimeBroadcastViewHeight kScaleFrom_iPhone5_Desgin(201)
13 | #define kDatePickerHeight (kTopViewHeight + kTimeBroadcastViewHeight + kSafeBottomMargin)
14 | #define kOKBtnTag 101
15 | #define kCancleBtnTag 100
16 |
17 | #import "HcdDateTimePickerView.h"
18 | #import "UIColor+HcdCustom.h"
19 |
20 | @interface HcdDateTimePickerView()
21 | {
22 | UIView *timeBroadcastView;//定时播放显示视图
23 | UIView *topView;
24 | UILabel *titleLbl;
25 | MXSCycleScrollView *yearScrollView;//年份滚动视图
26 | MXSCycleScrollView *monthScrollView;//月份滚动视图
27 | MXSCycleScrollView *dayScrollView;//日滚动视图
28 | MXSCycleScrollView *hourScrollView;//时滚动视图
29 | MXSCycleScrollView *minuteScrollView;//分滚动视图
30 | MXSCycleScrollView *secondScrollView;//秒滚动视图
31 | UIButton *okBtn;//自定义picker上的确认按钮
32 | UIButton *cancleBtn;//
33 | NSString *dateTimeStr;
34 | }
35 |
36 | @property (nonatomic,assign) NSInteger curYear;//当前年
37 | @property (nonatomic,assign) NSInteger curMonth;//当前月
38 | @property (nonatomic,assign) NSInteger curDay;//当前日
39 | @property (nonatomic,assign) NSInteger curHour;//当前小时
40 | @property (nonatomic,assign) NSInteger curMin;//当前分
41 | @property (nonatomic,assign) NSInteger curSecond;//当前秒
42 |
43 | @property (nonatomic, retain) NSDate *defaultDate;
44 |
45 | @end
46 |
47 | @implementation HcdDateTimePickerView
48 |
49 | - (instancetype)initWithDefaultDatetime:(NSDate *)dateTime
50 | {
51 | self = [super init];
52 | if (self) {
53 | self.defaultDate = dateTime;
54 | if (!self.defaultDate) {
55 | self.defaultDate = [NSDate date];
56 | }
57 | self.datePickerMode = DatePickerDateTimeMode;
58 | [self initDatas];
59 | [self setTimeBroadcastView];
60 | }
61 | return self;
62 | }
63 |
64 | - (instancetype)initWithDatePickerMode:(DatePickerMode)datePickerMode defaultDateTime:(NSDate *)dateTime
65 | {
66 | self = [super init];
67 | if (self) {
68 | self.defaultDate = dateTime;
69 | if (!self.defaultDate) {
70 | self.defaultDate = [NSDate date];
71 | }
72 | self.datePickerMode = datePickerMode;
73 | [self initDatas];
74 | [self setTimeBroadcastView];
75 | }
76 | return self;
77 | }
78 |
79 | - (void)setMaxYear:(NSInteger)maxYear {
80 | _maxYear = maxYear;
81 | [self updateYearScrollView];
82 | }
83 | - (void)setMinYear:(NSInteger)minYear {
84 | _minYear = minYear;
85 | [self updateYearScrollView];
86 | }
87 |
88 | - (void)updateYearScrollView {
89 | [yearScrollView reloadData];
90 |
91 | [yearScrollView setCurrentSelectPage:(self.curYear-(_minYear+2))];
92 | [self setAfterScrollShowView:yearScrollView andCurrentPage:1];
93 | }
94 |
95 | /*
96 | // Only override drawRect: if you perform custom drawing.
97 | // An empty implementation adversely affects performance during animation.
98 | - (void)drawRect:(CGRect)rect
99 | {
100 | // Drawing code
101 | }
102 | */
103 |
104 | - (void)initDatas {
105 | _topViewColor = [UIColor colorWithHexString:@"0x6271f3"];
106 | _buttonTitleColor = [UIColor colorWithHexString:@"0xffffff"];
107 | }
108 |
109 | - (void)setTopViewColor:(UIColor *)topViewColor {
110 | _topViewColor = topViewColor;
111 | if (topView) {
112 | topView.backgroundColor = topViewColor;
113 | }
114 | }
115 |
116 | - (void)setButtonTitleColor:(UIColor *)buttonTitleColor {
117 | _buttonTitleColor = buttonTitleColor;
118 | if (okBtn) {
119 | [okBtn setTitleColor:_buttonTitleColor forState:UIControlStateNormal];
120 | }
121 | if (cancleBtn) {
122 | [cancleBtn setTitleColor:_buttonTitleColor forState:UIControlStateNormal];
123 | }
124 | }
125 |
126 |
127 | - (void)setCancleColor:(UIColor *)cancleColor {
128 |
129 | _cancleColor = cancleColor;
130 | if (cancleBtn) {
131 | [cancleBtn setTitleColor:_cancleColor forState:UIControlStateNormal];
132 | }
133 | }
134 |
135 | - (void)setCancleText:(NSString *)cancleText {
136 | _cancleText = cancleText;
137 | if (cancleBtn) {
138 | [cancleBtn setTitle:_cancleText forState:UIControlStateNormal];
139 | }
140 | }
141 |
142 | - (void)setOkColor:(UIColor *)okColor {
143 | _okColor = okColor;
144 | if (okBtn) {
145 | [okBtn setTitleColor:_okColor forState:UIControlStateNormal];
146 | }
147 | }
148 |
149 | - (void)setOkText:(NSString *)okText {
150 | _okText = okText;
151 | if (okBtn) {
152 | [okBtn setTitle:_okText forState:UIControlStateNormal];
153 | }
154 | }
155 |
156 | - (void)setTitleColor:(UIColor *)titleColor
157 | {
158 | _titleColor = titleColor;
159 | titleLbl.textColor = _titleColor;
160 | }
161 |
162 | - (void)setTitle:(NSString *)title {
163 | _title = title;
164 | titleLbl.text = title;
165 | }
166 |
167 | #pragma mark -custompicker
168 | //设置自定义datepicker界面
169 | - (void)setTimeBroadcastView
170 | {
171 |
172 | [self setFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height)];
173 | [self setBackgroundColor:[UIColor clearColor]];
174 |
175 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
176 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
177 | dateTimeStr = [dateFormatter stringFromDate:self.defaultDate];
178 |
179 | topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, kTopViewHeight)];
180 | topView.backgroundColor = _topViewColor;
181 |
182 | okBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreen_Width-60, 0, 60, kTopViewHeight)];
183 | [okBtn setTitleColor:_buttonTitleColor forState:UIControlStateNormal];
184 | okBtn.titleLabel.font = [UIFont systemFontOfSize:14];
185 | [okBtn setBackgroundColor:[UIColor clearColor]];
186 | [okBtn setTitle:@"确定" forState:UIControlStateNormal];
187 | [okBtn addTarget:self action:@selector(selectedButtons:) forControlEvents:UIControlEventTouchUpInside];
188 | okBtn.tag = kOKBtnTag;
189 | [self addSubview:okBtn];
190 |
191 | cancleBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, kTopViewHeight)];
192 | cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
193 | [cancleBtn setTitleColor:_buttonTitleColor forState:UIControlStateNormal];
194 | [cancleBtn setBackgroundColor:[UIColor clearColor]];
195 | [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
196 | [cancleBtn addTarget:self action:@selector(selectedButtons:) forControlEvents:UIControlEventTouchUpInside];
197 | cancleBtn.tag = kCancleBtnTag;
198 | [self addSubview:cancleBtn];
199 |
200 | titleLbl = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, kScreen_Width - 120, kTopViewHeight)];
201 | titleLbl.textAlignment = NSTextAlignmentCenter;
202 | titleLbl.font = [UIFont systemFontOfSize:14];
203 |
204 | [topView addSubview:okBtn];
205 | [topView addSubview:cancleBtn];
206 | [topView addSubview:titleLbl];
207 |
208 | timeBroadcastView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kTimeBroadcastViewHeight)];
209 | timeBroadcastView.backgroundColor = [UIColor redColor];
210 | timeBroadcastView.layer.cornerRadius = 0;//设置视图圆角
211 | timeBroadcastView.layer.masksToBounds = YES;
212 | CGColorRef cgColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0].CGColor;
213 | timeBroadcastView.layer.borderColor = cgColor;
214 | timeBroadcastView.layer.borderWidth = 0.0;
215 | timeBroadcastView.backgroundColor = [UIColor whiteColor];
216 | [self addSubview:timeBroadcastView];
217 | UIView *beforeSepLine = [[UIView alloc] initWithFrame:CGRectMake(0, kTopViewHeight + floor(kTimeBroadcastViewHeight / 5), kScreen_Width, 0.5)];
218 | [beforeSepLine setBackgroundColor:[UIColor colorWithHexString:@"0xEDEDED"]];
219 | [timeBroadcastView addSubview:beforeSepLine];
220 | UIView *middleSepView = [[UIView alloc] initWithFrame:CGRectMake(0, kTopViewHeight + 2 * floor(kTimeBroadcastViewHeight / 5), kScreen_Width, floor(kTimeBroadcastViewHeight / 5))];
221 | [middleSepView setBackgroundColor:[UIColor colorWithHexString:@"0xEDEDED"]];
222 | [timeBroadcastView addSubview:middleSepView];
223 | middleSepView.layer.borderWidth = 0.5;
224 | middleSepView.layer.borderColor = [UIColor colorWithHexString:@"0xEDEDED"].CGColor;
225 | UIView *bottomSepLine = [[UIView alloc] initWithFrame:CGRectMake(0, kTopViewHeight + 4 * floor(kTimeBroadcastViewHeight / 5), kScreen_Width, 0.5)];
226 | [bottomSepLine setBackgroundColor:[UIColor colorWithHexString:@"0xEDEDED"]];
227 | [timeBroadcastView addSubview:bottomSepLine];
228 |
229 | if (self.datePickerMode == DatePickerDateMode) {
230 | [self setYearScrollView];
231 | [self setMonthScrollView];
232 | [self setDayScrollView];
233 | }
234 | else if (self.datePickerMode == DatePickerTimeMode) {
235 | [self setHourScrollView];
236 | [self setMinuteScrollView];
237 | [self setSecondScrollView];
238 | }
239 | else if (self.datePickerMode == DatePickerDateTimeMode) {
240 | [self setYearScrollView];
241 | [self setMonthScrollView];
242 | [self setDayScrollView];
243 | [self setHourScrollView];
244 | [self setMinuteScrollView];
245 | [self setSecondScrollView];
246 | }
247 | else if (self.datePickerMode == DatePickerYearMonthMode) {
248 | [self setYearScrollView];
249 | [self setMonthScrollView];
250 | }
251 | else if (self.datePickerMode == DatePickerMonthDayMode) {
252 | [self setMonthScrollView];
253 | [self setDayScrollView];
254 | }
255 | else if (self.datePickerMode == DatePickerHourMinuteMode) {
256 | [self setHourScrollView];
257 | [self setMinuteScrollView];
258 | }
259 | else if (self.datePickerMode == DatePickerDateHourMinuteMode) {
260 | [self setYearScrollView];
261 | [self setMonthScrollView];
262 | [self setDayScrollView];
263 | [self setHourScrollView];
264 | [self setMinuteScrollView];
265 | }
266 |
267 | [timeBroadcastView addSubview:topView];
268 | [timeBroadcastView setFrame:CGRectMake(0, kScreen_Height-100, kScreen_Width, kDatePickerHeight)];
269 | }
270 | //设置年月日时分的滚动视图
271 | - (void)setYearScrollView
272 | {
273 | if (self.datePickerMode == DatePickerDateTimeMode) {
274 | yearScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(0, kTopViewHeight, kScreen_Width*0.25, kTimeBroadcastViewHeight)];
275 | } else if (self.datePickerMode == DatePickerDateMode) {
276 | yearScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(0, kTopViewHeight, kScreen_Width*0.34, kTimeBroadcastViewHeight)];
277 | } else if (self.datePickerMode == DatePickerYearMonthMode) {
278 | yearScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(0, kTopViewHeight, kScreen_Width*0.5, kTimeBroadcastViewHeight)];
279 | } else if (self.datePickerMode == DatePickerDateHourMinuteMode) {
280 | yearScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(0, kTopViewHeight, kScreen_Width*0.28, kTimeBroadcastViewHeight)];
281 | }
282 |
283 | self.curYear = [self setNowTimeShow:0];
284 | [yearScrollView setCurrentSelectPage:(self.curYear-(_minYear+2))];
285 | yearScrollView.delegate = self;
286 | yearScrollView.datasource = self;
287 | [self setAfterScrollShowView:yearScrollView andCurrentPage:1];
288 | [timeBroadcastView addSubview:yearScrollView];
289 | }
290 | //设置年月日时分的滚动视图
291 | - (void)setMonthScrollView
292 | {
293 | if (self.datePickerMode == DatePickerDateTimeMode) {
294 | monthScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.25, kTopViewHeight, kScreen_Width*0.15, kTimeBroadcastViewHeight)];
295 | } else if (self.datePickerMode == DatePickerDateMode) {
296 | monthScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.34, kTopViewHeight, kScreen_Width*0.33, kTimeBroadcastViewHeight)];
297 | } else if (self.datePickerMode == DatePickerMonthDayMode) {
298 | monthScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0, kTopViewHeight, kScreen_Width*0.5, kTimeBroadcastViewHeight)];
299 | } else if (self.datePickerMode == DatePickerYearMonthMode) {
300 | monthScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.5, kTopViewHeight, kScreen_Width*0.5, kTimeBroadcastViewHeight)];
301 | } else if (self.datePickerMode == DatePickerDateHourMinuteMode) {
302 | monthScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.28, kTopViewHeight, kScreen_Width*0.18, kTimeBroadcastViewHeight)];
303 | }
304 |
305 | self.curMonth = [self setNowTimeShow:1];
306 | [monthScrollView setCurrentSelectPage:(self.curMonth-3)];
307 | monthScrollView.delegate = self;
308 | monthScrollView.datasource = self;
309 | [self setAfterScrollShowView:monthScrollView andCurrentPage:1];
310 | [timeBroadcastView addSubview:monthScrollView];
311 | }
312 | //设置年月日时分的滚动视图
313 | - (void)setDayScrollView
314 | {
315 | if (self.datePickerMode == DatePickerDateTimeMode) {
316 | dayScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.40, kTopViewHeight, kScreen_Width*0.15, kTimeBroadcastViewHeight)];
317 | } else if (self.datePickerMode == DatePickerDateMode) {
318 | dayScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.67, kTopViewHeight, kScreen_Width*0.33, kTimeBroadcastViewHeight)];
319 | } else if (self.datePickerMode == DatePickerMonthDayMode) {
320 | dayScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.5, kTopViewHeight, kScreen_Width*0.5, kTimeBroadcastViewHeight)];
321 | } else if (self.datePickerMode == DatePickerDateHourMinuteMode) {
322 | dayScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.46, kTopViewHeight, kScreen_Width*0.18, kTimeBroadcastViewHeight)];
323 | }
324 |
325 | self.curDay = [self setNowTimeShow:2];
326 | [dayScrollView setCurrentSelectPage:(self.curDay-3)];
327 | dayScrollView.delegate = self;
328 | dayScrollView.datasource = self;
329 | [self setAfterScrollShowView:dayScrollView andCurrentPage:1];
330 | [timeBroadcastView addSubview:dayScrollView];
331 | }
332 | //设置年月日时分的滚动视图
333 | - (void)setHourScrollView
334 | {
335 | if (self.datePickerMode == DatePickerDateTimeMode) {
336 | hourScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.55, kTopViewHeight, kScreen_Width*0.15, kTimeBroadcastViewHeight)];
337 | } else if (self.datePickerMode == DatePickerTimeMode) {
338 | hourScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(0, kTopViewHeight, kScreen_Width*0.34, kTimeBroadcastViewHeight)];
339 | } else if (self.datePickerMode == DatePickerHourMinuteMode) {
340 | hourScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(0, kTopViewHeight, kScreen_Width*0.5, kTimeBroadcastViewHeight)];
341 | } else if (self.datePickerMode == DatePickerDateHourMinuteMode) {
342 | hourScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.64, kTopViewHeight, kScreen_Width*0.18, kTimeBroadcastViewHeight)];
343 | }
344 |
345 | self.curHour = [self setNowTimeShow:3];
346 | [hourScrollView setCurrentSelectPage:(self.curHour-2)];
347 | hourScrollView.delegate = self;
348 | hourScrollView.datasource = self;
349 | [self setAfterScrollShowView:hourScrollView andCurrentPage:1];
350 | [timeBroadcastView addSubview:hourScrollView];
351 | }
352 | //设置年月日时分的滚动视图
353 | - (void)setMinuteScrollView
354 | {
355 | if (self.datePickerMode == DatePickerDateTimeMode) {
356 | minuteScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.70, kTopViewHeight, kScreen_Width*0.15, kTimeBroadcastViewHeight)];
357 | } else if (self.datePickerMode == DatePickerTimeMode) {
358 | minuteScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.34, kTopViewHeight, kScreen_Width*0.33, kTimeBroadcastViewHeight)];
359 | } else if (self.datePickerMode == DatePickerHourMinuteMode) {
360 | minuteScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.5, kTopViewHeight, kScreen_Width*0.5, kTimeBroadcastViewHeight)];
361 | } else if (self.datePickerMode == DatePickerDateHourMinuteMode) {
362 | minuteScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.82, kTopViewHeight, kScreen_Width*0.18, kTimeBroadcastViewHeight)];
363 | }
364 |
365 | self.curMin = [self setNowTimeShow:4];
366 | [minuteScrollView setCurrentSelectPage:(self.curMin-2)];
367 | minuteScrollView.delegate = self;
368 | minuteScrollView.datasource = self;
369 | [self setAfterScrollShowView:minuteScrollView andCurrentPage:1];
370 | [timeBroadcastView addSubview:minuteScrollView];
371 | }
372 | //设置年月日时分的滚动视图
373 | - (void)setSecondScrollView
374 | {
375 | if (self.datePickerMode == DatePickerDateTimeMode) {
376 | secondScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.85, kTopViewHeight, kScreen_Width*0.15, kTimeBroadcastViewHeight)];
377 | } else if (self.datePickerMode == DatePickerTimeMode) {
378 | secondScrollView = [[MXSCycleScrollView alloc] initWithFrame:CGRectMake(kScreen_Width*0.67, kTopViewHeight, kScreen_Width*0.33, kTimeBroadcastViewHeight)];
379 | }
380 | self.curSecond = [self setNowTimeShow:5];
381 | [secondScrollView setCurrentSelectPage:(self.curSecond-2)];
382 | secondScrollView.delegate = self;
383 | secondScrollView.datasource = self;
384 | [self setAfterScrollShowView:secondScrollView andCurrentPage:1];
385 | [timeBroadcastView addSubview:secondScrollView];
386 | }
387 | - (void)setAfterScrollShowView:(MXSCycleScrollView*)scrollview andCurrentPage:(NSInteger)pageNumber
388 | {
389 | UILabel *oneLabel = [[(UILabel*)[[scrollview subviews] objectAtIndex:0] subviews] objectAtIndex:pageNumber];
390 | [oneLabel setFont:[UIFont systemFontOfSize:14]];
391 | [oneLabel setTextColor:[UIColor colorWithHexString:@"0xBABABA"]];
392 | UILabel *twoLabel = [[(UILabel*)[[scrollview subviews] objectAtIndex:0] subviews] objectAtIndex:pageNumber+1];
393 | [twoLabel setFont:[UIFont systemFontOfSize:16]];
394 | [twoLabel setTextColor:[UIColor colorWithHexString:@"0x717171"]];
395 |
396 | UILabel *currentLabel = [[(UILabel*)[[scrollview subviews] objectAtIndex:0] subviews] objectAtIndex:pageNumber+2];
397 | [currentLabel setFont:[UIFont systemFontOfSize:18]];
398 | [currentLabel setTextColor:[UIColor blackColor]];
399 |
400 | UILabel *threeLabel = [[(UILabel*)[[scrollview subviews] objectAtIndex:0] subviews] objectAtIndex:pageNumber+3];
401 | [threeLabel setFont:[UIFont systemFontOfSize:16]];
402 | [threeLabel setTextColor:[UIColor colorWithHexString:@"0x717171"]];
403 | UILabel *fourLabel = [[(UILabel*)[[scrollview subviews] objectAtIndex:0] subviews] objectAtIndex:pageNumber+4];
404 | [fourLabel setFont:[UIFont systemFontOfSize:14]];
405 | [fourLabel setTextColor:[UIColor colorWithHexString:@"0xBABABA"]];
406 | }
407 | #pragma mark mxccyclescrollview delegate
408 | #pragma mark mxccyclescrollview databasesource
409 | - (NSInteger)numberOfPages:(MXSCycleScrollView*)scrollView
410 | {
411 | if (scrollView == yearScrollView) {
412 |
413 | if (self.datePickerMode == DatePickerDateMode || self.datePickerMode == DatePickerDateTimeMode) {
414 | return _maxYear - _minYear + 1;
415 | }
416 |
417 | return 299;
418 | }
419 | else if (scrollView == monthScrollView)
420 | {
421 | return 12;
422 | }
423 | else if (scrollView == dayScrollView)
424 | {
425 |
426 | if (DatePickerMonthDayMode == self.datePickerMode) {
427 | return 29;
428 | }
429 |
430 | if (self.curMonth == 1 || self.curMonth == 3 || self.curMonth == 5 ||
431 | self.curMonth == 7 || self.curMonth == 8 || self.curMonth == 10 ||
432 | self.curMonth == 12) {
433 | return 31;
434 | } else if (self.curMonth == 2) {
435 | if ([self isLeapYear:self.curYear]) {
436 | return 29;
437 | } else {
438 | return 28;
439 | }
440 | } else {
441 | return 30;
442 | }
443 | }
444 | else if (scrollView == hourScrollView)
445 | {
446 | return 24;
447 | }
448 | else if (scrollView == minuteScrollView)
449 | {
450 | return 60;
451 | }
452 | return 60;
453 | }
454 |
455 | - (UIView *)pageAtIndex:(NSInteger)index andScrollView:(MXSCycleScrollView *)scrollView
456 | {
457 | UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, scrollView.bounds.size.width, scrollView.bounds.size.height/5)];
458 | l.tag = index+1;
459 | if (scrollView == yearScrollView) {
460 | l.text = [NSString stringWithFormat:@"%ld",(long)(_minYear+index)];
461 | }
462 | else if (scrollView == monthScrollView)
463 | {
464 | if (index + 1 < 10) {
465 | l.text = [NSString stringWithFormat:@"0%ld",(long)(1 + index)];
466 | } else {
467 | l.text = [NSString stringWithFormat:@"%ld",(long)(1 + index)];
468 | }
469 | }
470 | else if (scrollView == dayScrollView)
471 | {
472 | if (index + 1 < 10) {
473 | l.text = [NSString stringWithFormat:@"0%ld",(long)(1 + index)];
474 | } else {
475 | l.text = [NSString stringWithFormat:@"%ld",(long)(1 + index)];
476 | }
477 | }
478 | else if (scrollView == hourScrollView)
479 | {
480 | if (index < 10) {
481 | l.text = [NSString stringWithFormat:@"0%ld",(long)index];
482 | }
483 | else
484 | l.text = [NSString stringWithFormat:@"%ld",(long)index];
485 | }
486 | else if (scrollView == minuteScrollView)
487 | {
488 | if (index < 10) {
489 | l.text = [NSString stringWithFormat:@"0%ld",(long)index];
490 | }
491 | else
492 | l.text = [NSString stringWithFormat:@"%ld",(long)index];
493 | }
494 | else
495 | if (index < 10) {
496 | l.text = [NSString stringWithFormat:@"0%ld",(long)index];
497 | }
498 | else
499 | l.text = [NSString stringWithFormat:@"%ld",(long)index];
500 |
501 | l.font = [UIFont systemFontOfSize:12];
502 | l.textAlignment = NSTextAlignmentCenter;
503 | l.backgroundColor = [UIColor clearColor];
504 | return l;
505 | }
506 | //设置现在时间
507 | - (NSInteger)setNowTimeShow:(NSInteger)timeType
508 | {
509 | NSDate *now = self.defaultDate;
510 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
511 | [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
512 | NSString *dateString = [dateFormatter stringFromDate:now];
513 | switch (timeType) {
514 | case 0:
515 | {
516 | NSRange range = NSMakeRange(0, 4);
517 | NSString *yearString = [dateString substringWithRange:range];
518 | return yearString.integerValue;
519 | }
520 | break;
521 | case 1:
522 | {
523 | NSRange range = NSMakeRange(4, 2);
524 | NSString *yearString = [dateString substringWithRange:range];
525 | return yearString.integerValue;
526 | }
527 | break;
528 | case 2:
529 | {
530 | NSRange range = NSMakeRange(6, 2);
531 | NSString *yearString = [dateString substringWithRange:range];
532 | return yearString.integerValue;
533 | }
534 | break;
535 | case 3:
536 | {
537 | NSRange range = NSMakeRange(8, 2);
538 | NSString *yearString = [dateString substringWithRange:range];
539 | return yearString.integerValue;
540 | }
541 | break;
542 | case 4:
543 | {
544 | NSRange range = NSMakeRange(10, 2);
545 | NSString *yearString = [dateString substringWithRange:range];
546 | return yearString.integerValue;
547 | }
548 | break;
549 | case 5:
550 | {
551 | NSRange range = NSMakeRange(12, 2);
552 | NSString *yearString = [dateString substringWithRange:range];
553 | return yearString.integerValue;
554 | }
555 | break;
556 | default:
557 | break;
558 | }
559 | return 0;
560 | }
561 | //选择设置的播报时间
562 | - (void)selectSetBroadcastTime
563 | {
564 | UILabel *yearLabel = [[(UILabel*)[[yearScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
565 | UILabel *monthLabel = [[(UILabel*)[[monthScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
566 | UILabel *dayLabel = [[(UILabel*)[[dayScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
567 | UILabel *hourLabel = [[(UILabel*)[[hourScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
568 | UILabel *minuteLabel = [[(UILabel*)[[minuteScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
569 | UILabel *secondLabel = [[(UILabel*)[[secondScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
570 |
571 | NSInteger yearInt = yearLabel.tag + _minYear - 1;
572 | NSInteger monthInt = monthLabel.tag;
573 | NSInteger dayInt = dayLabel.tag;
574 | NSInteger hourInt = hourLabel.tag - 1;
575 | NSInteger minuteInt = minuteLabel.tag - 1;
576 | NSInteger secondInt = secondLabel.tag - 1;
577 | NSString *taskDateString = [NSString stringWithFormat:@"%ld%02ld%02ld%02ld%02ld%02ld",(long)yearInt,(long)monthInt,(long)dayInt,(long)hourInt,(long)minuteInt,(long)secondInt];
578 | NSLog(@"Now----%@",taskDateString);
579 | }
580 | //滚动时上下标签显示(当前时间和是否为有效时间)
581 | - (void)scrollviewDidChangeNumber
582 | {
583 | UILabel *yearLabel = [[(UILabel*)[[yearScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
584 | UILabel *monthLabel = [[(UILabel*)[[monthScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
585 | UILabel *dayLabel = [[(UILabel*)[[dayScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
586 | UILabel *hourLabel = [[(UILabel*)[[hourScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
587 | UILabel *minuteLabel = [[(UILabel*)[[minuteScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
588 | UILabel *secondLabel = [[(UILabel*)[[secondScrollView subviews] objectAtIndex:0] subviews] objectAtIndex:3];
589 |
590 | NSInteger month = monthLabel.tag;
591 | NSInteger year = yearLabel.tag + _minYear - 1;
592 | if (month != self.curMonth) {
593 | self.curMonth = month;
594 | [dayScrollView reloadData];
595 | [dayScrollView setCurrentSelectPage:(self.curDay-3)];
596 | [self setAfterScrollShowView:dayScrollView andCurrentPage:1];
597 | }
598 | if (year != self.curYear) {
599 | self.curYear = year;
600 | [dayScrollView reloadData];
601 | [dayScrollView setCurrentSelectPage:(self.curDay-3)];
602 | [self setAfterScrollShowView:dayScrollView andCurrentPage:1];
603 | }
604 |
605 | self.curMonth = monthLabel.tag;
606 | self.curDay = dayLabel.tag;
607 | self.curHour = hourLabel.tag - 1;
608 | self.curMin = minuteLabel.tag - 1;
609 | self.curSecond = secondLabel.tag - 1;
610 |
611 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
612 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
613 | NSString *selectTimeString = [NSString stringWithFormat:@"%ld-%02ld-%02ld %02ld:%02ld:%02ld",(long)self.curYear,(long)self.curMonth,(long)self.curDay,(long)self.curHour,(long)self.curMin,(long)self.curSecond];
614 | NSDate *selectDate = [dateFormatter dateFromString:selectTimeString];
615 | NSDate *nowDate = self.defaultDate;
616 | NSString *nowString = [dateFormatter stringFromDate:nowDate];
617 | NSDate *nowStrDate = [dateFormatter dateFromString:nowString];
618 | if (NSOrderedAscending == [selectDate compare:nowStrDate]) {//选择的时间与当前系统时间做比较
619 | [okBtn setEnabled:YES];
620 | }
621 | else
622 | {
623 | [okBtn setEnabled:YES];
624 | }
625 | }
626 | //通过日期求星期
627 | - (NSString*)fromDateToWeek:(NSString*)selectDate
628 | {
629 | NSInteger yearInt = [selectDate substringWithRange:NSMakeRange(0, 4)].integerValue;
630 | NSInteger monthInt = [selectDate substringWithRange:NSMakeRange(4, 2)].integerValue;
631 | NSInteger dayInt = [selectDate substringWithRange:NSMakeRange(6, 2)].integerValue;
632 | int c = 20;//世纪
633 | NSInteger y = yearInt -1;//年
634 | NSInteger d = dayInt;
635 | NSInteger m = monthInt;
636 | int w =(y+(y/4)+(c/4)-2*c+(26*(m+1)/10)+d-1)%7;
637 | NSString *weekDay = @"";
638 | switch (w) {
639 | case 0:
640 | weekDay = @"周日";
641 | break;
642 | case 1:
643 | weekDay = @"周一";
644 | break;
645 | case 2:
646 | weekDay = @"周二";
647 | break;
648 | case 3:
649 | weekDay = @"周三";
650 | break;
651 | case 4:
652 | weekDay = @"周四";
653 | break;
654 | case 5:
655 | weekDay = @"周五";
656 | break;
657 | case 6:
658 | weekDay = @"周六";
659 | break;
660 | default:
661 | break;
662 | }
663 | return weekDay;
664 | }
665 |
666 | - (void)showHcdDateTimePicker
667 | {
668 | [UIView animateWithDuration:0.3f delay:0 usingSpringWithDamping:0.8f initialSpringVelocity:0 options:UIViewAnimationOptionLayoutSubviews animations:^{
669 |
670 | [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5f]];
671 | [self->timeBroadcastView setFrame:CGRectMake(0, kScreen_Height - kDatePickerHeight, kScreen_Width, kDatePickerHeight)];
672 |
673 | } completion:^(BOOL finished) {
674 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss:)];
675 | tap.delegate = self;
676 | [self addGestureRecognizer:tap];
677 |
678 | [self->timeBroadcastView setFrame:CGRectMake(0, kScreen_Height - kDatePickerHeight, kScreen_Width, kDatePickerHeight)];
679 | }];
680 | }
681 |
682 | -(void)dismissBlock:(DatePickerCompleteAnimationBlock)block{
683 |
684 | CGFloat height = kDatePickerHeight;
685 |
686 | [UIView animateWithDuration:0.4f delay:0 usingSpringWithDamping:0.8f initialSpringVelocity:0 options:UIViewAnimationOptionLayoutSubviews animations:^{
687 |
688 | [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.0f]];
689 | [self->timeBroadcastView setFrame:CGRectMake(0, kScreen_Height, kScreen_Width, height)];
690 |
691 | } completion:^(BOOL finished) {
692 |
693 | block(finished);
694 | [self removeFromSuperview];
695 |
696 | }];
697 |
698 | }
699 |
700 | -(void)dismiss:(UITapGestureRecognizer *)tap{
701 |
702 | if( CGRectContainsPoint(self.frame, [tap locationInView:timeBroadcastView])) {
703 | NSLog(@"tap");
704 | } else{
705 |
706 | [self dismissBlock:^(BOOL Complete) {
707 |
708 | }];
709 | }
710 | }
711 |
712 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
713 | if (touch.view != self) {
714 | return NO;
715 | }
716 |
717 | return YES;
718 | }
719 |
720 | -(void)selectedButtons:(UIButton *)btns{
721 |
722 | // typeof(self) __weak weak = self;
723 | [self dismissBlock:^(BOOL Complete) {
724 | if (btns.tag == kOKBtnTag) {
725 |
726 | switch (self.datePickerMode) {
727 | case DatePickerDateMode:
728 | self->dateTimeStr = [NSString stringWithFormat:@"%ld-%02ld-%02ld",(long)self.curYear,(long)self.curMonth,(long)self.curDay];
729 | break;
730 | case DatePickerTimeMode:
731 | self->dateTimeStr = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)self.curHour,(long)self.curMin,(long)self.curSecond];
732 | break;
733 | case DatePickerDateTimeMode:
734 | self->dateTimeStr = [NSString stringWithFormat:@"%ld-%ld-%ld %02ld:%02ld:%02ld",(long)self.curYear,(long)self.curMonth,(long)self.curDay,(long)self.curHour,(long)self.curMin,(long)self.curSecond];
735 | break;
736 | case DatePickerMonthDayMode:
737 | self->dateTimeStr = [NSString stringWithFormat:@"%ld-%ld",(long)self.curMonth,(long)self.curDay];
738 | break;
739 | case DatePickerYearMonthMode:
740 | self->dateTimeStr = [NSString stringWithFormat:@"%ld-%ld",(long)self.curYear,(long)self.curMonth];
741 | break;
742 | case DatePickerHourMinuteMode:
743 | self->dateTimeStr = [NSString stringWithFormat:@"%02ld:%02ld",(long)self.curHour,(long)self.curMin];
744 | break;
745 | case DatePickerDateHourMinuteMode:
746 | self->dateTimeStr = [NSString stringWithFormat:@"%ld-%ld-%ld %02ld:%02ld",(long)self.curYear,(long)self.curMonth,(long)self.curDay,(long)self.curHour,(long)self.curMin];
747 | break;
748 | default:
749 | self->dateTimeStr = [NSString stringWithFormat:@"%ld-%ld-%ld %02ld:%02ld:%02ld",(long)self.curYear,(long)self.curMonth,(long)self.curDay,(long)self.curHour,(long)self.curMin,(long)self.curSecond];
750 | break;
751 | }
752 |
753 | self.clickedOkBtn(self->dateTimeStr);
754 | } else {
755 |
756 | }
757 | }];
758 |
759 |
760 | }
761 |
762 | -(BOOL)isLeapYear:(NSInteger)year {
763 | if ((year%4==0 && year %100 !=0) || year%400==0) {
764 | return YES;
765 | }else {
766 | return NO;
767 | }
768 | return NO;
769 | }
770 |
771 | @end
772 |
--------------------------------------------------------------------------------