├── Screenshots
├── Screenshot1.png
└── Screenshot2.png
├── .slather.yml
├── CXDurationPickerDemo
├── Podfile.lock
├── Podfile
├── CXDurationPickerDemo
│ ├── Images.xcassets
│ │ ├── triangle_indicator.imageset
│ │ │ ├── triangle_indicator-1.png
│ │ │ ├── triangle_indicator.png
│ │ │ └── Contents.json
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── main.m
│ ├── AppDelegate.h
│ ├── ViewController.h
│ ├── Info.plist
│ ├── AppDelegate.m
│ ├── Base.lproj
│ │ ├── LaunchScreen.xib
│ │ └── Main.storyboard
│ └── ViewController.m
├── CXDurationPickerDemo.xcworkspace
│ └── contents.xcworkspacedata
├── CXDurationPickerDemoTests
│ ├── Info.plist
│ └── CXDurationPickerDemoTests.m
└── CXDurationPickerDemo.xcodeproj
│ ├── xcshareddata
│ └── xcschemes
│ │ └── CXDurationPickerDemo.xcscheme
│ └── project.pbxproj
├── .travis.yml
├── .gitignore
├── CXDurationPicker.podspec
├── CXDurationPicker
├── CXDurationPickerUtils.h
├── UIColor+CXDurationDefaults.h
├── CXDurationPickerDate.h
├── CXDurationPickerDayView.h
├── CXDurationPickerMonthView.h
├── UIColor+CXDurationDefaults.m
├── CXDurationPickerUtils.m
├── CXDurationPickerView.h
├── CXDurationPickerDayView.m
├── CXDurationPickerMonthView.m
└── CXDurationPickerView.m
├── README.md
└── LICENSE
/Screenshots/Screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/concurlabs/CXDurationPicker/HEAD/Screenshots/Screenshot1.png
--------------------------------------------------------------------------------
/Screenshots/Screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/concurlabs/CXDurationPicker/HEAD/Screenshots/Screenshot2.png
--------------------------------------------------------------------------------
/.slather.yml:
--------------------------------------------------------------------------------
1 | ci_service: travis_ci
2 | coverage_service: coveralls
3 | xcodeproj: CXDurationPickerDemo/CXDurationPickerDemo.xcodeproj
4 | source_directory: CXDurationPicker
5 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - CXTabView (0.3.2)
3 |
4 | DEPENDENCIES:
5 | - CXTabView (~> 0.3.2)
6 |
7 | SPEC CHECKSUMS:
8 | CXTabView: 07828630f993733fb9638d2aa95e773b40ea26f4
9 |
10 | COCOAPODS: 0.39.0
11 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/Podfile:
--------------------------------------------------------------------------------
1 | source 'https://github.com/CocoaPods/Specs.git'
2 | platform :ios, '7.0'
3 |
4 | target 'CXDurationPickerDemo' do
5 | pod 'CXTabView', '~> 0.3.2'
6 | end
7 |
8 | target 'CXDurationPickerDemoTests' do
9 | end
10 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/Images.xcassets/triangle_indicator.imageset/triangle_indicator-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/concurlabs/CXDurationPicker/HEAD/CXDurationPickerDemo/CXDurationPickerDemo/Images.xcassets/triangle_indicator.imageset/triangle_indicator-1.png
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/Images.xcassets/triangle_indicator.imageset/triangle_indicator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/concurlabs/CXDurationPicker/HEAD/CXDurationPickerDemo/CXDurationPickerDemo/Images.xcassets/triangle_indicator.imageset/triangle_indicator.png
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: objective-c
3 | osx_image: xcode7.2
4 | xcode_workspace: CXDurationPickerDemo/CXDurationPickerDemo.xcworkspace
5 | xcode_scheme: CXDurationPickerDemo
6 | xcode_sdk: iphonesimulator
7 | podfile: CXDurationPickerDemo/Podfile
8 |
9 | before_install:
10 | - gem install slather --no-ri --no-rdoc
11 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Mac OS X
2 | *.DS_Store
3 |
4 | # Xcode
5 | *.pbxuser
6 | *.mode1v3
7 | *.mode2v3
8 | *.perspectivev3
9 | *.xcuserstate
10 | *.xccheckout
11 | project.xcworkspace/
12 | xcuserdata/
13 |
14 | # Generated files
15 | *.o
16 | *.pyc
17 | Pods/
18 |
19 |
20 | #Python modules
21 | MANIFEST
22 | dist/
23 | build/
24 |
25 | # Backup files
26 | *~.nib
27 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // CXDurationPickerDemo
4 | //
5 | // Created by Richard Puckett on 3/8/15.
6 | // Copyright (c) 2015 Concur Labs. 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 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/Images.xcassets/triangle_indicator.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "triangle_indicator.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x",
11 | "filename" : "triangle_indicator-1.png"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/CXDurationPicker.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "CXDurationPicker"
3 | s.version = "0.16.10"
4 | s.summary = "Custom UIView which allows user to select a date range from calendar."
5 | s.homepage = "https://github.com/concurlabs/CXDurationPicker"
6 | s.license = "Apache 2"
7 | s.authors = { "Richard Puckett" => "richard.puckett@concur.com" }
8 | s.source = { :git => 'https://github.com/concurlabs/CXDurationPicker.git', :tag => s.version }
9 | s.ios.deployment_target = "7.0"
10 | s.source_files = "CXDurationPicker"
11 | s.ios.frameworks = "CoreText"
12 | s.requires_arc = true
13 | end
14 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | @interface AppDelegate : UIResponder
20 |
21 | @property (strong, nonatomic) UIWindow *window;
22 |
23 |
24 | @end
25 |
26 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemoTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.concur.labs.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 | #import
19 |
20 | #import "CXDurationPickerView.h"
21 |
22 | @interface ViewController : UIViewController
23 |
24 | @property (weak, nonatomic) IBOutlet CXTabView *tabView;
25 | @property (weak, nonatomic) IBOutlet CXDurationPickerView *picker;
26 | @property (weak, nonatomic) IBOutlet UIView *singleDateView;
27 | @property (weak, nonatomic) IBOutlet UILabel *singleDateViewLabel;
28 | @property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedModeSwitcher;
29 |
30 | @end
31 |
32 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | #import "CXDurationPickerDate.h"
20 |
21 | @interface CXDurationPickerUtils : NSObject
22 |
23 | + (NSDateComponents *)dateComponentsFromPickerDate:(CXDurationPickerDate)pickerDate;
24 | + (NSDate *)dateFromPickerDate:(CXDurationPickerDate)pickerDate;
25 | + (BOOL)isPickerDate:(CXDurationPickerDate)date1 equalTo:(CXDurationPickerDate)date2;
26 | + (CXDurationPickerDate)pickerDateFromDate:(NSDate *)date;
27 | + (CXDurationPickerDate)pickerDateShiftedByDays:(NSUInteger)days fromPickerDate:(CXDurationPickerDate)pickerDate;
28 | + (NSString *)stringFromPickerDate:(CXDurationPickerDate)pickerDate;
29 | + (NSDate *)today;
30 | + (BOOL)isPickerDateYesterday:(CXDurationPickerDate)pickerDate;
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/CXDurationPicker/UIColor+CXDurationDefaults.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | @interface UIColor (CXDurationDefaults)
20 |
21 | // Month-specific colors
22 | //
23 | + (UIColor *)defaultDayLabelColor;
24 | + (UIColor *)defaultMonthLabelColor;
25 |
26 | // Day-specific colors
27 | //
28 | + (UIColor *)defaultDayBackgroundColor;
29 | + (UIColor *)defaultDayForegroundColor;
30 |
31 | + (UIColor *)defaultDisabledDayBackgroundColor;
32 | + (UIColor *)defaultDisabledDayForegroundColor;
33 |
34 | + (UIColor *)defaultMonthBackgroundColor;
35 |
36 | + (UIColor *)defaultGridColor;
37 |
38 | + (UIColor *)defaultTerminalBackgroundColor;
39 | + (UIColor *)defaultTerminalForegroundColor;
40 |
41 | + (UIColor *)defaultTodayBackgroundColor;
42 | + (UIColor *)defaultTodayForegroundColor;
43 |
44 | + (UIColor *)defaultTransitBackgroundColor;
45 | + (UIColor *)defaultTransitForegroundColor;
46 |
47 | + (UIColor *)colorFromHexString:(NSString *)hexString;
48 | @end
49 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.concur.labs.$(PRODUCT_NAME:rfc1034identifier)
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 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerDate.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef CalendarViewSample_CXDurationPickerDate_h
18 | #define CalendarViewSample_CXDurationPickerDate_h
19 |
20 | #import
21 |
22 | typedef struct {
23 | NSUInteger year;
24 | NSUInteger month;
25 | NSUInteger day;
26 | } CXDurationPickerDate;
27 |
28 | typedef struct {
29 | NSUInteger year;
30 | NSUInteger month;
31 | } CXDurationPickerMonth;
32 |
33 | typedef NS_ENUM(NSUInteger, CXDurationPickerComparison) {
34 | CXDurationPickerComparisonEqual,
35 | CXDurationPickerComparisonBefore,
36 | CXDurationPickerComparisonAfter
37 | };
38 |
39 | typedef NS_ENUM(NSUInteger, CXDurationPickerMode) {
40 | CXDurationPickerModeSingleDate,
41 | CXDurationPickerModeStartDate,
42 | CXDurationPickerModeEndDate
43 | };
44 |
45 | typedef NS_ENUM(NSUInteger, CXDurationPickerDayType) {
46 | CXDurationPickerDayTypeDisabled,
47 | CXDurationPickerDayTypeStart,
48 | CXDurationPickerDayTypeEnd,
49 | CXDurationPickerDayTypeTransit,
50 | CXDurationPickerDayTypeNormal,
51 | CXDurationPickerDayTypeSingle,
52 | CXDurationPickerDayTypeOverlap
53 | };
54 |
55 | typedef NS_ENUM(NSUInteger, CXDurationPickerType) {
56 | CXDurationPickerTypeDuration,
57 | CXDurationPickerTypeSingle
58 | };
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerDayView.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | #import "CXDurationPickerDate.h"
20 | #import "CXDurationPickerView.h"
21 |
22 | @interface CXDurationPickerDayView : UIView
23 |
24 | @property (strong, nonatomic) NSString *day;
25 | @property (nonatomic) BOOL isDisabled;
26 | @property (nonatomic) BOOL isToday;
27 | @property (nonatomic) CXDurationPickerDate pickerDate;
28 | @property (nonatomic) CXDurationPickerDayType type;
29 |
30 | // Colors
31 | //
32 | @property (nonatomic)BOOL roundedTerminals;
33 |
34 | @property (strong, nonatomic) UIColor *dayBackgroundColor;
35 | @property (strong, nonatomic) UIColor *dayForegroundColor;
36 |
37 | @property (strong, nonatomic) UIColor *disabledDayBackgroundColor;
38 | @property (strong, nonatomic) UIColor *disabledDayForegroundColor;
39 |
40 | @property (strong, nonatomic) UIColor *gridColor;
41 |
42 | @property (strong, nonatomic) UIColor *terminalBackgroundColor;
43 | @property (strong, nonatomic) UIColor *terminalForegroundColor;
44 |
45 | @property (strong, nonatomic) UIColor *todayBackgroundColor;
46 | @property (strong, nonatomic) UIColor *todayForegroundColor;
47 |
48 | @property (strong, nonatomic) UIColor *transitBackgroundColor;
49 | @property (strong, nonatomic) UIColor *transitForegroundColor;
50 |
51 | // API
52 | //
53 | - (BOOL)isAfter:(CXDurationPickerDate)date;
54 | - (BOOL)isBefore:(CXDurationPickerDate)date;
55 | - (BOOL)isBetween:(CXDurationPickerDate)startDate and:(CXDurationPickerDate)endDate;
56 | - (BOOL)isPickerDate:(CXDurationPickerDate)pickerDate;
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/concurlabs/CXDurationPicker) [](https://coveralls.io/r/concurlabs/CXDurationPicker) [](http://cocoapods.org/?q=CXDurationPicker) [](http://cocoapods.org/?q=CXDurationPicker) [](LICENSE)
2 |
3 | # CXDurationPicker
4 | Custom iOS view for picking a date range
5 |
6 | 
7 |
8 | ## Installation with CocoaPods
9 | [CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like CXDurationPicker in your projects. See the [CocoaPods homepage for more information](https://cocoapods.org/).
10 |
11 | #### Podfile
12 | ```ruby
13 | platform :ios, '9.0'
14 | pod 'CXDurationPicker', "~> 0.16.10"
15 | ```
16 |
17 | ## Usage
18 | ### Colors
19 | Calendar colors can be changed in code by setting the following properties on CXDurationPickerView.
20 | 
21 |
22 | ## Demo Project
23 | There is a demo project which provides an example of interacting with CXDurationPickerView. To run this project please change into the CXDurationPicker project's folder and follow these steps:
24 |
25 | ```
26 | % cd CXDurationPickerDemo
27 | % pod install
28 | % open CXDurationPickerDemo.xcworkspace
29 |
30 | ```
31 |
32 | ## Collaboration
33 | If you have any feature requests/bugfixes etc. feel free to help out and send a pull request, or create a new issue.
34 |
35 | ## Maintainers
36 |
37 | - [Concur Labs](http://github.com/concurlabs)
38 |
39 | ## License
40 |
41 | Copyright 2015 - 2021 Concur
42 |
43 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
44 |
45 | http://www.apache.org/licenses/LICENSE-2.0
46 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
47 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import "AppDelegate.h"
18 |
19 | @interface AppDelegate ()
20 |
21 | @end
22 |
23 | @implementation AppDelegate
24 |
25 |
26 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
27 | // Override point for customization after application launch.
28 | return YES;
29 | }
30 |
31 | - (void)applicationWillResignActive:(UIApplication *)application {
32 | // 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.
33 | // 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.
34 | }
35 |
36 | - (void)applicationDidEnterBackground:(UIApplication *)application {
37 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
38 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
39 | }
40 |
41 | - (void)applicationWillEnterForeground:(UIApplication *)application {
42 | // 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.
43 | }
44 |
45 | - (void)applicationDidBecomeActive:(UIApplication *)application {
46 | // 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.
47 | }
48 |
49 | - (void)applicationWillTerminate:(UIApplication *)application {
50 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerMonthView.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | #import "CXDurationPickerDate.h"
20 | #import "CXDurationPickerView.h"
21 |
22 | @class CXDurationPickerDayView;
23 | @class CXDurationPickerMonthView;
24 |
25 | @protocol CXDurationPickerMonthViewDelegate
26 |
27 | - (void)monthView:(CXDurationPickerMonthView *)view daySelected:(CXDurationPickerDayView *)dayView;
28 |
29 | @end
30 |
31 | @interface CXDurationPickerMonthView : UIView
32 |
33 | @property (weak, nonatomic) id delegate;
34 | @property (strong, nonatomic) NSMutableArray *days;
35 | @property (nonatomic) NSInteger monthIndex;
36 | @property (nonatomic) UIEdgeInsets padding;
37 | @property (nonatomic) CXDurationPickerMonth pickerMonth;
38 | @property (nonatomic) BOOL disableDaysBeforeToday;
39 | @property (nonatomic) BOOL disableYesterday;
40 |
41 | @property (nonatomic,strong)NSMutableSet* blockedDays;
42 | // Month-specific colors
43 | //
44 | @property (strong, nonatomic) UIColor *dayLabelColor;
45 | @property (strong, nonatomic) UIColor *monthLabelColor;
46 |
47 | // Day-specific colors
48 | //
49 | @property (strong, nonatomic) UIColor *dayBackgroundColor;
50 | @property (strong, nonatomic) UIColor *dayForegroundColor;
51 |
52 | @property (strong, nonatomic) UIColor *disabledDayBackgroundColor;
53 | @property (strong, nonatomic) UIColor *disabledDayForegroundColor;
54 |
55 | @property (strong, nonatomic) UIColor *gridColor;
56 |
57 | @property (strong, nonatomic) UIColor *terminalBackgroundColor;
58 | @property (strong, nonatomic) UIColor *terminalForegroundColor;
59 |
60 | @property (strong, nonatomic) UIColor *todayBackgroundColor;
61 | @property (strong, nonatomic) UIColor *todayForegroundColor;
62 |
63 | @property (strong, nonatomic) UIColor *transitBackgroundColor;
64 | @property (strong, nonatomic) UIColor *transitForegroundColor;
65 |
66 | @property (nonatomic)BOOL roundedTerminals;
67 |
68 | - (BOOL)containsDate:(CXDurationPickerDate)pickerDate;
69 | - (CXDurationPickerDayView *)dayForPickerDate:(CXDurationPickerDate)pickerDate;
70 | -(void)assignBlockedDays:(NSArray *)disabledDays;
71 | @end
72 |
--------------------------------------------------------------------------------
/CXDurationPicker/UIColor+CXDurationDefaults.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import "UIColor+CXDurationDefaults.h"
18 |
19 | @implementation UIColor (Defaults)
20 |
21 | #pragma mark - Month-specific Colors
22 |
23 | + (UIColor *)defaultDayLabelColor {
24 | return [UIColor colorWithRed:127/255.0 green:143/255.0 blue:151/255.0 alpha:1];
25 | }
26 |
27 | + (UIColor *)defaultMonthLabelColor {
28 | return [UIColor colorWithRed:56/255.0 green:63/255.0 blue:70/255.0 alpha:1];
29 | }
30 |
31 | #pragma mark - Day-specific Colors
32 |
33 | + (UIColor *)defaultDayBackgroundColor {
34 | return [UIColor whiteColor];
35 | }
36 |
37 | + (UIColor *)defaultDayForegroundColor {
38 | return [UIColor darkGrayColor];
39 | }
40 |
41 | + (UIColor *)defaultDisabledDayBackgroundColor {
42 | return [UIColor colorWithRed:255/255.0
43 | green:150/255.0
44 | blue:150/255.0
45 | alpha:0.1];
46 | }
47 |
48 | + (UIColor *)defaultDisabledDayForegroundColor {
49 | return [UIColor darkGrayColor];
50 | }
51 |
52 | + (UIColor *)defaultMonthBackgroundColor {
53 | return [UIColor whiteColor];
54 | }
55 |
56 | + (UIColor *)defaultGridColor {
57 | return [UIColor grayColor];
58 | }
59 |
60 | + (UIColor *)defaultTerminalBackgroundColor {
61 | return [UIColor colorWithRed:0
62 | green:120/255.0
63 | blue:200/255.0
64 | alpha:1];
65 | }
66 |
67 | + (UIColor *)defaultTerminalForegroundColor {
68 | return [UIColor whiteColor];
69 | }
70 |
71 | + (UIColor *)defaultTodayBackgroundColor {
72 | return [UIColor colorWithRed:198/255.0
73 | green:208/255.0
74 | blue:214/255.0
75 | alpha:0.5];
76 | }
77 |
78 | + (UIColor *)defaultTodayForegroundColor {
79 | return [UIColor darkGrayColor];
80 | }
81 |
82 | + (UIColor *)defaultTransitBackgroundColor {
83 | return [UIColor colorWithRed:0
84 | green:120/255.0
85 | blue:200/255.0
86 | alpha:0.25];
87 | }
88 |
89 | + (UIColor *)defaultTransitForegroundColor {
90 | return [UIColor darkGrayColor];
91 | }
92 |
93 | + (UIColor *)colorFromHexString:(NSString *)hexString {
94 | unsigned rgbValue = 0;
95 | NSScanner *scanner = [NSScanner scannerWithString:hexString];
96 | [scanner setScanLocation:1]; // bypass '#' character
97 | [scanner scanHexInt:&rgbValue];
98 | return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:0.3];
99 | }
100 |
101 | @end
102 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerUtils.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import "CXDurationPickerDate.h"
18 | #import "CXDurationPickerUtils.h"
19 |
20 | @implementation CXDurationPickerUtils
21 |
22 | + (NSDateComponents *)dateComponentsFromPickerDate:(CXDurationPickerDate)pickerDate {
23 |
24 | if (pickerDate.year == 0) return nil;
25 |
26 | NSDateComponents *components = [NSDateComponents new];
27 |
28 | components.year = pickerDate.year;
29 | components.month = pickerDate.month;
30 | components.day = pickerDate.day;
31 |
32 | return components;
33 | }
34 |
35 | + (NSDate *)dateFromPickerDate:(CXDurationPickerDate)pickerDate {
36 |
37 | if (pickerDate.year == 0) return nil;
38 |
39 | NSCalendar *calendar = [NSCalendar currentCalendar];
40 |
41 | return [calendar dateFromComponents:[CXDurationPickerUtils dateComponentsFromPickerDate:pickerDate]];
42 | }
43 |
44 | + (BOOL)isPickerDate:(CXDurationPickerDate)date1 equalTo:(CXDurationPickerDate)date2 {
45 | return date1.year == date2.year
46 | && date1.month == date2.month
47 | && date1.day == date2.day;
48 | }
49 |
50 | + (CXDurationPickerDate)pickerDateFromDate:(NSDate *)date {
51 |
52 | if (date == nil) return (CXDurationPickerDate){0,0,0};
53 |
54 | NSCalendar *calendar = [NSCalendar currentCalendar];
55 |
56 | NSDateComponents *components = [calendar
57 | components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
58 | fromDate:date];
59 |
60 | return (CXDurationPickerDate) {
61 | components.year,
62 | components.month,
63 | components.day
64 | };
65 | }
66 |
67 | + (CXDurationPickerDate)pickerDateShiftedByDays:(NSUInteger)days fromPickerDate:(CXDurationPickerDate)pickerDate {
68 | NSDate *startDate = [CXDurationPickerUtils dateFromPickerDate:pickerDate];
69 |
70 | NSCalendar *calendar = [NSCalendar currentCalendar];
71 |
72 | NSDateComponents *components = [NSDateComponents new];
73 |
74 | components.day = days;
75 |
76 | NSDate *shiftedDate = [calendar dateByAddingComponents:components toDate:startDate options:0];
77 |
78 | return [CXDurationPickerUtils pickerDateFromDate:shiftedDate];
79 | }
80 |
81 | + (NSString *)stringFromPickerDate:(CXDurationPickerDate)pickerDate {
82 |
83 | if (pickerDate.year == 0) return nil;
84 |
85 | NSDate *date = [CXDurationPickerUtils dateFromPickerDate:pickerDate];
86 |
87 | NSDateFormatter *formatter = [NSDateFormatter new];
88 |
89 | [formatter setDateStyle:NSDateFormatterMediumStyle];
90 | [formatter setTimeStyle:NSDateFormatterNoStyle];
91 |
92 | return [formatter stringFromDate:date];
93 | }
94 |
95 | + (NSDate *)today {
96 | NSDate *date = [NSDate date];
97 |
98 | NSCalendar *calendar = [NSCalendar currentCalendar];
99 |
100 | NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
101 | fromDate:date];
102 |
103 | return [calendar dateFromComponents:components];
104 | }
105 |
106 | + (BOOL)isPickerDateYesterday:(CXDurationPickerDate)pickerDate {
107 | NSDate *today = [self today];
108 | NSDate *date = [self dateFromPickerDate:pickerDate];
109 |
110 | NSTimeInterval interval = [date timeIntervalSinceDate:today];
111 |
112 | // 86400 seconds = 24hrs
113 | if ( interval >= -86400 && interval < 0) {
114 | return YES;
115 | }
116 |
117 | return NO;
118 | }
119 |
120 | @end
121 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerView.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | #import "CXDurationPickerDate.h"
20 | #import "CXDurationPickerMonthView.h"
21 |
22 | @class CXDurationPickerView;
23 |
24 | @protocol CXDurationPickerViewDelegate
25 |
26 | @optional
27 |
28 | - (void)durationPicker:(CXDurationPickerView *)durationPicker endDateChanged:(CXDurationPickerDate)date;
29 | - (void)durationPicker:(CXDurationPickerView *)durationPicker singleDateChanged:(CXDurationPickerDate)date;
30 | - (void)durationPicker:(CXDurationPickerView *)durationPicker startDateChanged:(CXDurationPickerDate)date;
31 |
32 | - (void)durationPicker:(CXDurationPickerView *)durationPicker invalidEndDateSelected:(CXDurationPickerDate)date;
33 | - (void)durationPicker:(CXDurationPickerView *)durationPicker invalidStartDateSelected:(CXDurationPickerDate)date;
34 |
35 | - (void)durationPicker:(CXDurationPickerView *)durationPicker
36 | didSelectDateInPast:(CXDurationPickerDate)date
37 | forMode:(CXDurationPickerMode)mode;
38 |
39 | @end
40 |
41 | @interface CXDurationPickerView : UIView
42 |
43 | @property (weak, nonatomic) id delegate;
44 | @property (nonatomic) CXDurationPickerDate singleDate;
45 | @property (nonatomic) CXDurationPickerDate startDate;
46 | @property (nonatomic) CXDurationPickerDate endDate;
47 | @property (nonatomic) CXDurationPickerMode mode;
48 | @property (nonatomic) CXDurationPickerType type;
49 | @property (nonatomic) BOOL allowSelectionsInPast;
50 | @property (nonatomic) BOOL allowSelectionOnSameDay;
51 | @property (nonatomic) BOOL allowSelectionOfYesterdayAsStartDay;
52 |
53 | @property (nonatomic,strong)NSArray* blockedDays;
54 |
55 | // Month-specific colors
56 | //
57 | @property (strong, nonatomic) UIColor *dayLabelColor;
58 | @property (strong, nonatomic) UIColor *monthLabelColor;
59 |
60 | // Day-specific colors
61 | //
62 | @property (strong, nonatomic) UIColor *dayBackgroundColor;
63 | @property (strong, nonatomic) UIColor *dayForegroundColor;
64 |
65 | @property (strong, nonatomic) UIColor *disabledDayBackgroundColor;
66 | @property (strong, nonatomic) UIColor *disabledDayForegroundColor;
67 |
68 | @property (strong, nonatomic) UIColor *gridColor;
69 |
70 | @property (strong, nonatomic) UIColor *terminalBackgroundColor;
71 | @property (strong, nonatomic) UIColor *terminalForegroundColor;
72 |
73 | @property (strong, nonatomic) UIColor *todayBackgroundColor;
74 | @property (strong, nonatomic) UIColor *todayForegroundColor;
75 |
76 | @property (strong, nonatomic) UIColor *transitBackgroundColor;
77 | @property (strong, nonatomic) UIColor *transitForegroundColor;
78 |
79 | @property (nonatomic)BOOL roundedTerminals;
80 |
81 | - (void)scrollToStartMonth:(BOOL)animated;
82 |
83 | // Maintained for backward-compat. Will be removed in v1.0
84 | //
85 | - (void)shiftDurationToEndPickerDate:(CXDurationPickerDate)pickerDate __attribute__((deprecated));
86 | - (void)shiftDurationToStartPickerDate:(CXDurationPickerDate)pickerDate __attribute__((deprecated));
87 |
88 | - (BOOL)shiftDurationToEndPickerDate:(CXDurationPickerDate)pickerDate error:(NSError **)error;
89 | - (BOOL)shiftDurationToStartPickerDate:(CXDurationPickerDate)pickerDate error:(NSError **)error;
90 |
91 | - (void)setStartDate:(NSDate *)date withDuration:(NSUInteger)days;
92 | - (void)setStartPickerDate:(CXDurationPickerDate)pickerDate withDuration:(NSUInteger)days;
93 |
94 | - (void)clearCurrentDuration;
95 | - (void)clearSingle;
96 | - (BOOL)hasStartDate;
97 | - (BOOL)hasEndDate;
98 | - (BOOL)hasEitherStartOrEndDate;
99 | @end
100 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo.xcodeproj/xcshareddata/xcschemes/CXDurationPickerDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
45 |
46 |
48 |
54 |
55 |
56 |
57 |
58 |
64 |
65 |
66 |
67 |
68 |
69 |
79 |
81 |
87 |
88 |
89 |
90 |
91 |
92 |
98 |
100 |
106 |
107 |
108 |
109 |
111 |
112 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/ViewController.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import "CXDurationPickerUtils.h"
18 | #import "ViewController.h"
19 |
20 | @interface ViewController ()
21 |
22 | @end
23 |
24 | @implementation ViewController
25 |
26 | - (void)viewDidLoad {
27 | [super viewDidLoad];
28 |
29 | self.tabView.delegate = self;
30 | self.picker.delegate = self;
31 |
32 | self.picker.mode = CXDurationPickerModeStartDate;
33 |
34 | // CXDurationPickerDate endPickerDate;
35 | // endPickerDate.day = 23;
36 | // endPickerDate.month = 5;
37 | // endPickerDate.year = 2015;
38 | //
39 | // [self.picker setStartDate:endPickerDate];
40 | //
41 | // self.picker.mode = CXDurationPickerModeStartDate;
42 | //
43 | // CXDurationPickerDate startPickerDate;
44 | // startPickerDate.day = 19;
45 | // startPickerDate.month = 5;
46 | // startPickerDate.year = 2015;
47 | //
48 | // [self.picker setStartDate:startPickerDate];
49 | //
50 | // [self.picker setStartPickerDate:d withDuration:5];
51 |
52 | // An example that will change the picker's background color.
53 | //
54 | //self.view.backgroundColor = [UIColor greenColor];
55 | //self.picker.backgroundColor = [UIColor clearColor];
56 |
57 | self.picker.allowSelectionsInPast = YES;
58 |
59 | [self synchronizeComponents];
60 | }
61 |
62 | #pragma mark - CXTabViewDelegate
63 |
64 | - (void)tabView:(CXTabView *)tabView didSelectMode:(CXTabViewMode)mode {
65 | switch (mode) {
66 | case CXTabViewModeStart:
67 | NSLog(@"Selected start mode");
68 | self.picker.mode = CXDurationPickerModeStartDate;
69 | break;
70 | case CXTabViewModeEnd:
71 | NSLog(@"Selected end mode");
72 | self.picker.mode = CXDurationPickerModeEndDate;
73 | break;
74 | }
75 | }
76 |
77 | #pragma mark - CXDurationPickerViewDelegate
78 |
79 | - (void)durationPicker:(CXDurationPickerView *)durationPicker
80 | endDateChanged:(CXDurationPickerDate)pickerDate {
81 |
82 | self.tabView.durationEndString = [CXDurationPickerUtils stringFromPickerDate:pickerDate];
83 | }
84 |
85 | - (void)durationPicker:(CXDurationPickerView *)durationPicker
86 | singleDateChanged:(CXDurationPickerDate)pickerDate {
87 |
88 | self.singleDateViewLabel.text = [CXDurationPickerUtils stringFromPickerDate:pickerDate];
89 |
90 | NSLog(@"Selected single date of %@", [CXDurationPickerUtils stringFromPickerDate:pickerDate]);
91 | }
92 |
93 | - (void)durationPicker:(CXDurationPickerView *)durationPicker
94 | startDateChanged:(CXDurationPickerDate)pickerDate {
95 |
96 | self.tabView.durationStartString = [CXDurationPickerUtils stringFromPickerDate:pickerDate];
97 | }
98 |
99 | #pragma mark - CXDurationPickerViewDelegate Optionals
100 |
101 | - (void)durationPicker:(CXDurationPickerView *)durationPicker
102 | invalidEndDateSelected:(CXDurationPickerDate)date {
103 |
104 | NSLog(@"Invalid end date selected.");
105 |
106 | NSError *error;
107 |
108 | BOOL didShift = [self.picker shiftDurationToEndPickerDate:date error:&error];
109 |
110 | if (didShift) {
111 | [self synchronizeComponents];
112 | } else {
113 | NSLog(@"Unable to shift end date: %@", error.localizedDescription);
114 | }
115 | }
116 |
117 | - (void)durationPicker:(CXDurationPickerView *)durationPicker invalidStartDateSelected:(CXDurationPickerDate)date {
118 | NSLog(@"Invalid start date selected.");
119 |
120 | NSError *error;
121 |
122 | BOOL didShift = [self.picker shiftDurationToStartPickerDate:date error:&error];
123 |
124 | if (didShift) {
125 | [self synchronizeComponents];
126 | } else {
127 | NSLog(@"Unable to shift start date: %@", error.localizedDescription);
128 | }
129 | }
130 |
131 | - (void)durationPicker:(CXDurationPickerView *)durationPicker
132 | didSelectDateInPast:(CXDurationPickerDate)date
133 | forMode:(CXDurationPickerMode)mode {
134 |
135 | NSLog(@"Date was selected in the past. Ignoring.");
136 | }
137 |
138 | #pragma mark - Segmented Mode Switcher
139 |
140 | - (IBAction)segmentedModeSwitcherChanged {
141 | if (self.segmentedModeSwitcher.selectedSegmentIndex == 0) {
142 | self.tabView.alpha = 1;
143 | self.singleDateView.alpha = 0;
144 | self.picker.type = CXDurationPickerTypeDuration;
145 | self.tabView.mode = CXTabViewModeStart;
146 | } else if (self.segmentedModeSwitcher.selectedSegmentIndex == 1) {
147 | self.tabView.alpha = 0;
148 | self.singleDateView.alpha = 1;
149 | self.picker.type = CXDurationPickerTypeSingle;
150 | }
151 |
152 | [self synchronizeComponents];
153 | }
154 |
155 | #pragma mark - Utilities
156 |
157 | - (void)synchronizeComponents {
158 | if (self.segmentedModeSwitcher.selectedSegmentIndex == 0) {
159 | [self synchronizeRange];
160 | } else if (self.segmentedModeSwitcher.selectedSegmentIndex == 1) {
161 | [self synchronizeSingle];
162 | }
163 | }
164 |
165 | - (void)synchronizeRange {
166 | CXDurationPickerDate startDate = self.picker.startDate;
167 | self.tabView.durationStartString = [CXDurationPickerUtils stringFromPickerDate:startDate];
168 |
169 | CXDurationPickerDate endDate = self.picker.endDate;
170 | self.tabView.durationEndString = [CXDurationPickerUtils stringFromPickerDate:endDate];
171 | }
172 |
173 | - (void)synchronizeSingle {
174 | CXDurationPickerDate pickerDate = self.picker.singleDate;
175 | self.singleDateViewLabel.text = [CXDurationPickerUtils stringFromPickerDate:pickerDate];
176 | }
177 |
178 | @end
179 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemoTests/CXDurationPickerDemoTests.m:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | #import "CXDurationPickerDate.h"
5 | #import "CXDurationPickerUtils.h"
6 | #import "CXDurationPickerView.h"
7 | #import "CXDurationPickerDayView.h"
8 | @interface CXDurationPickerDemoTests : XCTestCase
9 |
10 | @end
11 |
12 | @implementation CXDurationPickerDemoTests
13 |
14 | - (void)setUp {
15 | [super setUp];
16 | }
17 |
18 | - (void)tearDown {
19 | [super tearDown];
20 | }
21 |
22 | - (void)testExample {
23 | XCTAssert(YES, @"Pass");
24 | }
25 |
26 | - (void)testUtilComponents {
27 | CXDurationPickerDate pickerDate;
28 | pickerDate.day = 1;
29 | pickerDate.month = 1;
30 | pickerDate.year = 2015;
31 |
32 | NSDateComponents *testComponents = [CXDurationPickerUtils dateComponentsFromPickerDate:pickerDate];
33 |
34 | XCTAssertEqual(testComponents.day, 1, @"Incorrect day returned.");
35 | XCTAssertEqual(testComponents.month, 1, @"Incorrect month returned.");
36 | XCTAssertEqual(testComponents.year, 2015, @"Incorrect year returned.");
37 | }
38 |
39 | - (void)testUtilToday {
40 | NSDate *t1 = [CXDurationPickerUtils today];
41 |
42 | NSDate *t2 = [NSDate date];
43 |
44 | NSCalendar *calendar = [NSCalendar currentCalendar];
45 |
46 | NSDateComponents *c1 = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
47 | fromDate:t1];
48 |
49 | NSDateComponents *c2 = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
50 | fromDate:t2];
51 |
52 | XCTAssertEqual(c1.day, c2.day, "Day is not the same");
53 | XCTAssertEqual(c1.month, c2.month, "Month is not the same");
54 | XCTAssertEqual(c1.year, c2.year, "Year is not the same");
55 | }
56 |
57 |
58 | - (void)testUtilYesterday {
59 | NSDate *today = [NSDate date];
60 | NSDate *yesterday = [today dateByAddingTimeInterval: -86400.0];
61 | NSCalendar *calendar = [NSCalendar currentCalendar];
62 |
63 | NSDateComponents *comps =
64 | [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay
65 | fromDate:yesterday];
66 |
67 | CXDurationPickerDate pickerYesterday;
68 | pickerYesterday.day = comps.day;
69 | pickerYesterday.month = comps.month;
70 | pickerYesterday.year = comps.year;
71 |
72 | BOOL isDateYesterday = [CXDurationPickerUtils isPickerDateYesterday:pickerYesterday];
73 |
74 | XCTAssert(isDateYesterday, "Date is not yesterday");
75 |
76 | // Now give it todays date, and see if it still thinks it is yesterday
77 | comps =
78 | [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay
79 | fromDate:today];
80 |
81 | pickerYesterday.day = comps.day;
82 | pickerYesterday.month = comps.month;
83 | pickerYesterday.year = comps.year;
84 |
85 | isDateYesterday = [CXDurationPickerUtils isPickerDateYesterday:pickerYesterday];
86 |
87 | XCTAssert(!isDateYesterday, "Date is yesterday");
88 |
89 | // Now give it tomorrows date, and see if it still thinks it is yesterday
90 | NSDate *tomorrow = [today dateByAddingTimeInterval: 86400.0];
91 | comps =
92 | [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay
93 | fromDate:tomorrow];
94 |
95 | pickerYesterday.day = comps.day;
96 | pickerYesterday.month = comps.month;
97 | pickerYesterday.year = comps.year;
98 |
99 | isDateYesterday = [CXDurationPickerUtils isPickerDateYesterday:pickerYesterday];
100 |
101 | XCTAssert(!isDateYesterday, "Date is yesterday");
102 |
103 | }
104 | -(void)testDayViewCanBeInstanciated{
105 |
106 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
107 |
108 | XCTAssertNotNil(view);
109 | XCTAssertTrue(view.roundedTerminals); //Default rounded
110 | }
111 |
112 | -(void)testDrawInRec_typeStart{
113 |
114 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
115 | view.day = @"1";
116 | view.type = CXDurationPickerDayTypeStart;
117 | XCTAssertNoThrow([view drawRect:view.frame]);
118 | }
119 | -(void)testDrawInRec_typeEnd{
120 |
121 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
122 | view.day = @"1";
123 | view.type = CXDurationPickerDayTypeEnd;
124 | XCTAssertNoThrow([view drawRect:view.frame]);
125 | }
126 |
127 | -(void)testDrawInRec_typeTransit{
128 |
129 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
130 | view.day = @"1";
131 | view.type = CXDurationPickerDayTypeTransit;
132 | XCTAssertNoThrow([view drawRect:view.frame]);
133 | }
134 |
135 | -(void)testDrawInRec_typeNormal{
136 |
137 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
138 | view.day = @"1";
139 | view.type = CXDurationPickerDayTypeTransit;
140 | XCTAssertNoThrow([view drawRect:view.frame]);
141 | }
142 |
143 | -(void)testDrawInRec_typeSinge{
144 |
145 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
146 | view.day = @"1";
147 | view.type = CXDurationPickerDayTypeSingle;
148 | XCTAssertNoThrow([view drawRect:view.frame]);
149 | }
150 |
151 | -(void)testDrawInRec_typeOverlap{
152 |
153 | CXDurationPickerDayView* view = [[CXDurationPickerDayView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
154 | view.day = @"1";
155 | view.type = CXDurationPickerDayTypeOverlap;
156 | XCTAssertNoThrow([view drawRect:view.frame]);
157 | }
158 |
159 | -(NSArray*)generateDaysFromTomorrow:(NSUInteger)numberOfDay{
160 | NSMutableArray* daysArray = [NSMutableArray new];
161 |
162 | NSDate *tomorrow = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:[NSDate date]];
163 |
164 | [daysArray addObject:tomorrow];
165 |
166 | for (NSUInteger dayNo = 1; dayNo < numberOfDay; dayNo ++) {
167 | NSDate *nextDay = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:tomorrow];
168 | [daysArray addObject:nextDay];
169 | }
170 |
171 | return daysArray.copy;
172 | }
173 |
174 |
175 | @end
176 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo/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 |
27 |
28 |
29 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerDayView.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | #import "CXDurationPickerDayView.h"
20 | #import "CXDurationPickerUtils.h"
21 | #import "UIColor+CXDurationDefaults.h"
22 |
23 | @interface CXDurationPickerDayView ()
24 |
25 | @end
26 |
27 | @implementation CXDurationPickerDayView
28 |
29 | - (void)baseInit {
30 | self.contentMode = UIViewContentModeRedraw;
31 |
32 | self.opaque = NO;
33 |
34 | self.isToday = NO;
35 |
36 | self.type = CXDurationPickerDayTypeNormal;
37 |
38 | self.dayBackgroundColor = [UIColor defaultDayBackgroundColor];
39 | self.dayForegroundColor = [UIColor defaultDayForegroundColor];
40 | self.disabledDayBackgroundColor = [UIColor defaultDisabledDayBackgroundColor];
41 | self.disabledDayForegroundColor = [UIColor defaultDisabledDayForegroundColor];
42 | self.gridColor = [UIColor defaultGridColor];
43 | self.terminalBackgroundColor = [UIColor defaultTerminalBackgroundColor];
44 | self.terminalForegroundColor = [UIColor defaultTerminalForegroundColor];
45 | self.todayBackgroundColor = [UIColor defaultTodayBackgroundColor];
46 | self.todayForegroundColor = [UIColor defaultTodayForegroundColor];
47 | self.transitBackgroundColor = [UIColor defaultTransitBackgroundColor];
48 | self.transitForegroundColor = [UIColor defaultTransitForegroundColor];
49 | self.roundedTerminals = YES;
50 | }
51 |
52 | - (NSString *)description {
53 | return [CXDurationPickerUtils stringFromPickerDate:self.pickerDate];
54 | }
55 |
56 | - (id)initWithFrame:(CGRect)frame {
57 | self = [super initWithFrame:frame];
58 |
59 | if (self) {
60 | [self baseInit];
61 | }
62 |
63 | return self;
64 | }
65 |
66 | - (void)drawRect:(CGRect)rect {
67 | CGContextRef context = UIGraphicsGetCurrentContext();
68 |
69 | CGContextSetLineWidth(context, 1);
70 |
71 | // Draw highlighted background.
72 | //
73 | // If we're an overlap then don't draw the background as that will overwrite
74 | // any previous day grpahics.
75 | //
76 | if (self.isToday) {
77 | CGContextSetFillColorWithColor(context, self.todayBackgroundColor.CGColor);
78 |
79 | CGContextFillRect(context, CGRectMake(0.5, 0.5,
80 | self.bounds.size.width - 1,
81 | self.bounds.size.height - 1));
82 | } else if (self.isDisabled) {
83 | CGContextSetFillColorWithColor(context, self.disabledDayBackgroundColor.CGColor);
84 |
85 | CGContextFillRect(context, CGRectMake(0.5, 0.5,
86 | self.bounds.size.width - 1,
87 | self.bounds.size.height - 1));
88 | } else {
89 | CGContextSetFillColorWithColor(context, self.dayBackgroundColor.CGColor);
90 |
91 | CGContextFillRect(context, CGRectMake(0.5, 0.5,
92 | self.bounds.size.width - 1,
93 | self.bounds.size.height - 1));
94 | }
95 |
96 | // Draw calendar day border.
97 | //
98 | CGContextSetStrokeColorWithColor(context, self.gridColor.CGColor);
99 |
100 | CGContextStrokeRect(context, CGRectMake(0.5, 0.5,
101 | self.bounds.size.width - 1,
102 | self.bounds.size.height - 1));
103 |
104 | [self drawText:self.day];
105 |
106 | #ifdef COMPONENTS_DEMO
107 | [self setIsAccessibilityElement:YES];
108 |
109 | if (self.accessibilityIdentifier.length == 0) {
110 |
111 | self.accessibilityIdentifier = [NSString stringWithFormat:@"%@ %@ %@",@(self.pickerDate.year).stringValue, @(self.pickerDate.month).stringValue, @(self.pickerDate.day).stringValue];
112 |
113 | NSLog(@"dateID:%@",self.accessibilityIdentifier);
114 | self.accessibilityValue = @(self.type).stringValue;
115 | }
116 | #endif
117 |
118 | }
119 |
120 | - (void)drawText:(NSString *)label {
121 | #ifdef COMPONENTS_DEMO
122 | [self setAccessibilityLabel:self.description];
123 | #endif
124 | CGContextRef context = UIGraphicsGetCurrentContext();
125 |
126 | CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem,
127 | self.bounds.size.height / 3, NULL);
128 |
129 | CGFloat ascenderHeight = CTFontGetAscent(font);
130 |
131 | // Set foreground text color.
132 | //
133 | CGColorRef color;
134 |
135 | if (self.type == CXDurationPickerDayTypeStart
136 | || self.type == CXDurationPickerDayTypeEnd
137 | || self.type == CXDurationPickerDayTypeSingle
138 | || self.type == CXDurationPickerDayTypeOverlap) {
139 | color = self.terminalForegroundColor.CGColor;
140 | } else if (self.isDisabled) {
141 | color = self.disabledDayForegroundColor.CGColor;
142 | } else if (self.type == CXDurationPickerDayTypeTransit) {
143 | color = self.transitForegroundColor.CGColor;
144 | } else {
145 | if (self.isToday) {
146 | color = self.todayForegroundColor.CGColor;
147 | } else {
148 | color = self.dayForegroundColor.CGColor;
149 | }
150 |
151 | }
152 |
153 | NSDictionary *attributesDict = [NSDictionary dictionaryWithObjectsAndKeys:
154 | (__bridge id)font, (id)kCTFontAttributeName,
155 | color, (id)kCTForegroundColorAttributeName,
156 | nil];
157 |
158 | NSAttributedString *stringToDraw = [[NSAttributedString alloc] initWithString:label
159 | attributes:attributesDict];
160 |
161 |
162 | // Flip the coordinate system.
163 | //
164 | CGContextSetTextMatrix(context, CGAffineTransformIdentity);
165 | CGContextTranslateCTM(context, 0, self.bounds.size.height);
166 | CGContextScaleCTM(context, 1.0, -1.0);
167 |
168 | CGSize size = [self labelSize:stringToDraw];
169 |
170 | float labelWidth = size.width;
171 |
172 | // Draw rectangle for start day.
173 | //
174 | if (self.type == CXDurationPickerDayTypeStart) {
175 | float notBiggerThan = self.bounds.size.height * 0.60;
176 | float notSmallerThan = ascenderHeight + 5;
177 |
178 | float rectangleHeight = fmaxf(notBiggerThan, notSmallerThan);
179 | float rectangleWidth = self.bounds.size.width / 2;
180 |
181 | float rectangleY = (self.bounds.size.height - rectangleHeight) / 2;
182 | float rectangleX = rectangleWidth;
183 |
184 | CGContextSetFillColorWithColor(context, self.transitBackgroundColor.CGColor);
185 |
186 | CGContextFillRect(context, CGRectMake(rectangleX + 0.5,
187 | rectangleY + 0.5,
188 | rectangleWidth - 1,
189 | rectangleHeight - 1));
190 |
191 | } else if (self.type == CXDurationPickerDayTypeEnd) {
192 | float notBiggerThan = self.bounds.size.height * 0.60;
193 | float notSmallerThan = ascenderHeight + 5;
194 |
195 | float rectangleHeight = fmaxf(notBiggerThan, notSmallerThan);
196 | float rectangleWidth = self.bounds.size.width / 2;
197 |
198 | float rectangleY = (self.bounds.size.height - rectangleHeight) / 2;
199 |
200 | CGContextSetFillColorWithColor(context, self.transitBackgroundColor.CGColor);
201 |
202 | CGContextFillRect(context, CGRectMake(0.5,
203 | rectangleY + 0.5,
204 | rectangleWidth - 1,
205 | rectangleHeight - 1));
206 |
207 | } else if (self.type == CXDurationPickerDayTypeTransit) {
208 |
209 | if (self.roundedTerminals) {
210 | float notBiggerThan = self.bounds.size.height * 0.60;
211 | float notSmallerThan = ascenderHeight + 5;
212 |
213 | float rectangleHeight = fmaxf(notBiggerThan, notSmallerThan);
214 |
215 | float rectangleY = (self.bounds.size.height - rectangleHeight) / 2;
216 |
217 | CGContextSetFillColorWithColor(context, self.transitBackgroundColor.CGColor);
218 |
219 | CGContextFillRect(context, CGRectMake(0.5,
220 | rectangleY + 0.5,
221 | self.frame.size.width - 1,
222 | rectangleHeight - 1));
223 | } else {
224 | CGContextSetFillColorWithColor(context, self.transitBackgroundColor.CGColor);
225 |
226 | CGContextFillRect(context, CGRectMake(0.5, 0.5,
227 | self.bounds.size.width - 1,
228 | self.bounds.size.height - 1));
229 | }
230 | }
231 |
232 | // Draw circle.
233 | //
234 | if (self.type == CXDurationPickerDayTypeStart
235 | || self.type == CXDurationPickerDayTypeEnd
236 | || self.type == CXDurationPickerDayTypeSingle
237 | || self.type == CXDurationPickerDayTypeOverlap) {
238 |
239 | if (self.roundedTerminals) {
240 | float notBiggerThan = self.bounds.size.height * 0.60;
241 | float notSmallerThan = ascenderHeight + 5;
242 |
243 | float circleDiameter = fmaxf(notBiggerThan, notSmallerThan);
244 |
245 | float circleX = (self.bounds.size.width - circleDiameter) / 2;
246 | float circleY = (self.bounds.size.height - circleDiameter) / 2;
247 |
248 | CGContextSetFillColorWithColor(context, self.terminalBackgroundColor.CGColor);
249 |
250 | CGContextBeginPath(context);
251 | CGContextAddEllipseInRect(context, CGRectMake(circleX, circleY, circleDiameter, circleDiameter));
252 | CGContextDrawPath(context, kCGPathFill);
253 | } else {
254 | CGContextSetFillColorWithColor(context, self.terminalBackgroundColor.CGColor);
255 |
256 | CGContextFillRect(context, CGRectMake(0.5, 0.5,
257 | self.bounds.size.width - 1,
258 | self.bounds.size.height - 1));
259 | }
260 |
261 | }
262 |
263 | if (self.type == CXDurationPickerDayTypeOverlap) {
264 |
265 | if (self.roundedTerminals) {
266 | float notBiggerThan = self.bounds.size.height * 0.80;
267 | float notSmallerThan = ascenderHeight + 7;
268 |
269 | float circleDiameter = fmaxf(notBiggerThan, notSmallerThan);
270 | float circleRadius = circleDiameter / 2;
271 |
272 | float circleX = (self.bounds.size.width - circleDiameter) / 2 + circleRadius;
273 | float circleY = (self.bounds.size.height - circleDiameter) / 2 + circleRadius;
274 |
275 | CGContextSetStrokeColorWithColor(context, self.terminalBackgroundColor.CGColor);
276 | CGContextSetLineWidth(context, 2);
277 | CGContextAddArc(context, circleX, circleY, circleRadius, 0, M_PI * 2, false);
278 | CGContextStrokePath(context);
279 | } else {
280 | CGContextSetFillColorWithColor(context, self.terminalBackgroundColor.CGColor);
281 |
282 | CGContextFillRect(context, CGRectMake(0.5, 0.5,
283 | self.bounds.size.width - 1,
284 | self.bounds.size.height - 1));
285 | }
286 |
287 | }
288 |
289 | // Draw day number.
290 | //
291 | float xOffset = (self.bounds.size.width - labelWidth) / 2;
292 | float yCenter = (self.bounds.size.height - ascenderHeight) / 2;
293 |
294 | // I can't find the right way to vertically align the text, but adding a couple DIPs here
295 | // makes it look right. :/
296 | //
297 | float yOffset = (yCenter + 3);
298 |
299 | CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)stringToDraw);
300 | CGContextSetTextPosition(context, xOffset, yOffset);
301 | CTLineDraw(line, context);
302 |
303 | CFRelease(line);
304 | CFRelease(font);
305 |
306 |
307 | self.accessibilityValue = @(self.type).stringValue;
308 | }
309 |
310 | - (BOOL)isAfter:(CXDurationPickerDate)date {
311 | NSDate *myDate = [CXDurationPickerUtils dateFromPickerDate:self.pickerDate];
312 | NSDate *otherDate = [CXDurationPickerUtils dateFromPickerDate:date];
313 |
314 | return [myDate timeIntervalSinceDate:otherDate] > 0;
315 | }
316 |
317 | - (BOOL)isBefore:(CXDurationPickerDate)date {
318 | NSDate *myDate = [CXDurationPickerUtils dateFromPickerDate:self.pickerDate];
319 | NSDate *otherDate = [CXDurationPickerUtils dateFromPickerDate:date];
320 |
321 | return [myDate timeIntervalSinceDate:otherDate] < 0;
322 | }
323 |
324 | - (BOOL)isBetween:(CXDurationPickerDate)startDate and:(CXDurationPickerDate)endDate {
325 | if (_pickerDate.year <= endDate.year
326 | && _pickerDate.month <= endDate.month
327 | && _pickerDate.day <= endDate.day
328 | && _pickerDate.year >= startDate.year
329 | && _pickerDate.month >= startDate.month
330 | && _pickerDate.day >= startDate.day) {
331 |
332 | return YES;
333 | }
334 |
335 | return NO;
336 | }
337 |
338 | - (BOOL)isPickerDate:(CXDurationPickerDate)pickerDate {
339 | return _pickerDate.year == pickerDate.year
340 | && _pickerDate.month == pickerDate.month
341 | && _pickerDate.day == pickerDate.day;
342 | }
343 |
344 | - (CGSize)labelSize:(NSAttributedString *)label {
345 | CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(label));
346 |
347 | CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(
348 | frameSetter,
349 | CFRangeMake(0, label.length),
350 | NULL,
351 | CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX),
352 | NULL
353 | );
354 |
355 | return suggestedSize;
356 | }
357 |
358 | - (void)setType:(CXDurationPickerDayType)type {
359 | _type = type;
360 |
361 | [self setNeedsDisplay];
362 | }
363 |
364 | @end
365 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerMonthView.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import
18 |
19 | #import "CXDurationPickerView.h"
20 | #import "CXDurationPickerDayView.h"
21 | #import "CXDurationPickerMonthView.h"
22 | #import "CXDurationPickerUtils.h"
23 | #import "UIColor+CXDurationDefaults.h"
24 |
25 | @interface CXDurationPickerMonthView ()
26 | @property (strong, nonatomic) NSDate *date;
27 | @property (strong, nonatomic) NSString *dateString;
28 | @property (strong, nonatomic, strong) NSCalendar *calendar;
29 | @property (nonatomic) CGFloat cellWidth;
30 | @property (nonatomic) CGFloat cellHeight;
31 | @property (nonatomic) CGFloat monthWidth;
32 | @property (nonatomic) CGFloat monthOffset;
33 | @property (nonatomic) CGFloat monthTitleHeight;
34 | @property (nonatomic) CGFloat weekTitleHeight;
35 | @property (strong, nonatomic) UILabel *dateLabel;
36 | @property (nonatomic) NSDateComponents *components;
37 | @property (nonatomic) NSUInteger numDays;
38 | @end
39 |
40 | @implementation CXDurationPickerMonthView
41 |
42 | #pragma mark - Lifecycle
43 |
44 | - (void)baseInit {
45 | self.monthTitleHeight = 16;
46 | self.weekTitleHeight = 12;
47 |
48 | self.gridColor = [UIColor grayColor];
49 |
50 | self.days = [[NSMutableArray alloc] init];
51 |
52 | self.blockedDays = [NSMutableSet new];
53 |
54 | self.monthWidth = (floor(self.bounds.size.width / 7) * 7) - 6;
55 |
56 | self.monthOffset = (self.bounds.size.width - self.monthWidth) / 2;
57 |
58 | self.backgroundColor = [UIColor defaultMonthBackgroundColor];
59 |
60 | self.calendar = [NSCalendar currentCalendar];
61 |
62 | self.roundedTerminals = YES;
63 | }
64 |
65 | - (NSString *)description {
66 | return self.dateString;
67 | }
68 |
69 | -(void)assignBlockedDays:(NSArray *)disabledDays{
70 | NSMutableSet* componentArray = [NSMutableSet new];
71 | for (NSDate* date in disabledDays) {
72 | NSDateComponents *todayComponents = [[NSCalendar currentCalendar]
73 | components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
74 | fromDate:date];
75 | [componentArray addObject:todayComponents];
76 | }
77 | _blockedDays = componentArray.copy;
78 | }
79 |
80 | - (id)initWithCoder:(NSCoder *)decoder {
81 | self = [super initWithCoder:decoder];
82 |
83 | if (self) {
84 | [self baseInit];
85 | }
86 |
87 | return self;
88 | }
89 |
90 | - (id)initWithFrame:(CGRect)frame {
91 | self = [super initWithFrame:frame];
92 |
93 | if (self) {
94 | [self baseInit];
95 | }
96 |
97 | return self;
98 | }
99 |
100 | - (void)layoutSubviews {
101 | if (!self.date) {
102 | NSLog(@"monthview layout: Nothing to do.");
103 | return;
104 | }
105 |
106 | NSDate *today = [NSDate date];
107 | NSDateComponents *todayComponents = [[NSCalendar currentCalendar]
108 | components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
109 | fromDate:today];
110 | NSDate *yesterday = [today dateByAddingTimeInterval: -86400.0];
111 | NSDateComponents *yesterdayComponents = [[NSCalendar currentCalendar]
112 | components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
113 | fromDate:yesterday];
114 |
115 | float cellSize = self.bounds.size.width / 7;
116 |
117 | self.cellWidth = floor(cellSize);
118 | self.cellHeight = floor(cellSize);
119 |
120 | self.dateLabel.frame = CGRectMake(self.monthOffset, 0,
121 | self.bounds.size.width - self.monthOffset,
122 | self.monthTitleHeight + 4);
123 |
124 | float yOffset = self.dateLabel.frame.size.height + 10;
125 |
126 | for (int i = 0; i < 7; i++) {
127 | float xOffset = 0;
128 |
129 | if (i != 0) {
130 | xOffset = -1 * i;
131 | }
132 |
133 | NSUInteger tag = 100 + i;
134 |
135 | UIView *dayLabel = [self viewWithTag:tag];
136 |
137 | dayLabel.frame = CGRectMake(i * self.cellWidth + self.monthOffset + xOffset,
138 | yOffset,
139 | self.cellWidth,
140 | self.weekTitleHeight);
141 | }
142 |
143 | yOffset += self.weekTitleHeight + 5;
144 |
145 | int colIndex = 0;
146 | int rowIndex = 0;
147 |
148 | for (int i = 1; i < self.components.weekday; i++) {
149 | colIndex++;
150 | }
151 |
152 | for (int i = 0; i < self.numDays; i++) {
153 | float x = colIndex * self.cellWidth;
154 | float y = rowIndex * self.cellHeight;
155 |
156 | float xOffset = 0;
157 |
158 | if (colIndex != 0) {
159 | xOffset = -1 * (colIndex);
160 | }
161 |
162 | float yOffset2 = 0;
163 | if (rowIndex != 0) {
164 | yOffset2 = -1 * (rowIndex);
165 | }
166 |
167 | NSUInteger tag = 200 + i;
168 |
169 | CXDurationPickerDayView *dayView = (CXDurationPickerDayView*)[self viewWithTag:tag];
170 |
171 | dayView.frame = CGRectMake(x + self.monthOffset + xOffset,
172 | y + yOffset + yOffset2,
173 | self.cellWidth,
174 | self.cellHeight);
175 |
176 | colIndex++;
177 |
178 | if (colIndex % 7 == 0) {
179 | colIndex = 0;
180 | rowIndex++;
181 | }
182 |
183 | if (self.disableDaysBeforeToday) {
184 | if (self.components.year < todayComponents.year) {
185 | dayView.isDisabled = YES;
186 | } else if (self.components.year <= todayComponents.year
187 | && self.components.month < todayComponents.month) {
188 | dayView.isDisabled = YES;
189 | } else if (self.components.year == yesterdayComponents.year
190 | && self.components.month == yesterdayComponents.month
191 | && i == yesterdayComponents.day - 1
192 | && !self.disableYesterday) {
193 | dayView.isDisabled = NO;
194 | } else if (self.components.year == todayComponents.year
195 | && self.components.month == todayComponents.month
196 | && i < todayComponents.day - 1) {
197 | dayView.isDisabled = YES;
198 | }
199 | } else {
200 | dayView.isDisabled = NO;
201 | }
202 |
203 | //Disable Day here
204 | if (self.blockedDays.count > 0 ) {
205 | NSDateComponents *dayComponent = [CXDurationPickerUtils dateComponentsFromPickerDate:dayView.pickerDate];
206 | if ([self.blockedDays containsObject:dayComponent]) {
207 | dayView.isDisabled = YES;
208 | dayView.type = CXDurationPickerDayTypeDisabled;
209 | }
210 | }
211 |
212 | dayView.roundedTerminals = self.roundedTerminals;
213 |
214 | }
215 | }
216 |
217 | - (CGSize)sizeThatFits:(CGSize)size {
218 | float cellSize = self.bounds.size.width / 7;
219 |
220 | self.cellWidth = floor(cellSize);
221 | self.cellHeight = floor(cellSize);
222 |
223 | NSUInteger height = 0;
224 |
225 | height += (self.dateLabel.frame.size.height + 10);
226 | height += (self.weekTitleHeight + 5);
227 |
228 | NSUInteger numWeeks = [self numberOfWeekRowsNeeded];
229 |
230 | height += (numWeeks * self.cellHeight);
231 |
232 | height += 20; // bottom
233 |
234 | CGSize viewSize = CGSizeMake(self.bounds.size.width, height);
235 |
236 | return viewSize;
237 | }
238 |
239 | #pragma mark - Gesture recognizers
240 |
241 | - (void)daySelected:(UITapGestureRecognizer *)recognizer {
242 | if (self.delegate != nil) {
243 | CXDurationPickerDayView *dayView = (CXDurationPickerDayView *)recognizer.view;
244 | if (!dayView.isDisabled) {
245 | [self.delegate monthView:self daySelected:dayView];
246 | }
247 |
248 | }
249 | }
250 |
251 | #pragma mark - Internal
252 |
253 | - (BOOL)containsDate:(CXDurationPickerDate)pickerDate {
254 | if (self.pickerMonth.month == pickerDate.month
255 | && self.pickerMonth.year == pickerDate.year) {
256 | return YES;
257 | }
258 |
259 | return NO;
260 | }
261 |
262 | - (CXDurationPickerDayView *)dayForPickerDate:(CXDurationPickerDate)pickerDate {
263 | CXDurationPickerDayView *day;
264 |
265 | for (CXDurationPickerDayView *dayView in self.days) {
266 | if (dayView.pickerDate.day == pickerDate.day) {
267 | day = dayView;
268 | break;
269 | }
270 | }
271 |
272 | return day;
273 | }
274 |
275 | - (void)setupViews {
276 | self.dateString = [NSString stringWithFormat:@"%@", [self monthNameFromDate:self.date]];
277 |
278 | UIFont *dateFont = [UIFont fontWithName:@"HelveticaNeue" size:self.monthTitleHeight];
279 |
280 | // [self setIsAccessibilityElement:YES];
281 | // self.accessibilityIdentifier = self.dateString;
282 |
283 | self.dateLabel = [[UILabel alloc] init];
284 |
285 | [self.dateLabel setFont:dateFont];
286 | [self.dateLabel setTextAlignment:NSTextAlignmentCenter];
287 | [self.dateLabel setTextColor:self.monthLabelColor];
288 | [self.dateLabel setText:self.dateString];
289 |
290 | [self addSubview:self.dateLabel];
291 |
292 | // Build a localized string array instead of hardcoded SUN,MON...FRI,SAT,SUN
293 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
294 | NSMutableArray *daysOfWeek = [[NSMutableArray alloc] init];
295 | for (NSString *dayOfWeek in [dateFormatter shortWeekdaySymbols]) {
296 | [daysOfWeek addObject:[dayOfWeek uppercaseString]];
297 | }
298 | // Add SUN to the end again - not sure why, but the hardcoded array had it there, so if it ain't broke...
299 | [daysOfWeek addObject:daysOfWeek[0]];
300 |
301 | UILabel *dayLabel;
302 | UIFont *dayFont = [UIFont fontWithName:@"HelveticaNeue" size:self.weekTitleHeight];
303 |
304 | for (int i = 0; i < 7; i++) {
305 | float xOffset = 0;
306 |
307 | if (i != 0) {
308 | xOffset = -1 * i;
309 | }
310 |
311 | NSUInteger tag = 100 + i;
312 |
313 | dayLabel = [[UILabel alloc] init];
314 |
315 | [dayLabel setTag:tag];
316 | [dayLabel setFont:dayFont];
317 | [dayLabel setTextAlignment:NSTextAlignmentCenter];
318 | [dayLabel setTextColor:self.dayLabelColor];
319 | [dayLabel setFont:dayFont];
320 | [dayLabel setText:daysOfWeek[i]];
321 |
322 | [self addSubview:dayLabel];
323 | }
324 |
325 | int colIndex = 0;
326 | int rowIndex = 0;
327 |
328 | for (int i = 1; i < self.components.weekday; i++) {
329 | colIndex++;
330 | }
331 |
332 | NSDate *today = [NSDate date];
333 | NSDateComponents *todayComponents = [[NSCalendar currentCalendar]
334 | components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
335 | fromDate:today];
336 | NSDate *yesterday = [today dateByAddingTimeInterval: -86400.0];
337 | NSDateComponents *yesterdayComponents = [[NSCalendar currentCalendar]
338 | components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
339 | fromDate:yesterday];
340 |
341 | for (int i = 0; i < self.numDays; i++) {
342 | float xOffset = 0;
343 |
344 | if (colIndex != 0) {
345 | xOffset = -1 * (colIndex);
346 | }
347 |
348 | float yOffset2 = 0;
349 | if (rowIndex != 0) {
350 | yOffset2 = -1 * (rowIndex);
351 | }
352 |
353 | CXDurationPickerDayView *v = [[CXDurationPickerDayView alloc] init];
354 |
355 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
356 | action:@selector(daySelected:)];
357 |
358 | [v addGestureRecognizer:tap];
359 |
360 | if (self.disableDaysBeforeToday) {
361 | if (self.components.year < todayComponents.year) {
362 | v.isDisabled = YES;
363 | } else if (self.components.year <= todayComponents.year
364 | && self.components.month < todayComponents.month) {
365 | v.isDisabled = YES;
366 | } else if (self.components.year == yesterdayComponents.year
367 | && self.components.month == yesterdayComponents.month
368 | && i == yesterdayComponents.day - 1
369 | && !self.disableYesterday) {
370 | v.isDisabled = NO;
371 | } else if (self.components.year == todayComponents.year
372 | && self.components.month == todayComponents.month
373 | && i < todayComponents.day - 1) {
374 | v.isDisabled = YES;
375 | }
376 | } else {
377 | v.isDisabled = NO;
378 | }
379 |
380 | if (self.components.year == todayComponents.year
381 | && self.components.month == todayComponents.month
382 | && i == todayComponents.day - 1) {
383 | v.isToday = YES;
384 | }
385 |
386 | colIndex++;
387 |
388 | v.tag = 200 + i;
389 |
390 | NSString *day = [NSString stringWithFormat:@"%d", i + 1];
391 |
392 | v.day = day;
393 |
394 | CXDurationPickerDate pickerDate;
395 | pickerDate.day = i + 1;
396 | pickerDate.month = self.pickerMonth.month;
397 | pickerDate.year = self.pickerMonth.year;
398 |
399 | v.pickerDate = pickerDate;
400 |
401 | v.gridColor = self.gridColor;
402 |
403 | [self.days addObject:v];
404 |
405 | [self addSubview:v];
406 |
407 | if (colIndex % 7 == 0) {
408 | colIndex = 0;
409 | rowIndex++;
410 | }
411 | }
412 | }
413 |
414 | - (void)setMonthIndex:(NSInteger)index {
415 | _monthIndex = index;
416 |
417 | self.date = [self dateForFirstDayInSection:index];
418 |
419 | self.pickerMonth = [self monthPickerDateFromDate:self.date];
420 |
421 | NSCalendar *c = [NSCalendar currentCalendar];
422 |
423 | self.numDays = [c rangeOfUnit:NSCalendarUnitDay
424 | inUnit:NSCalendarUnitMonth
425 | forDate:self.date].length;
426 |
427 | self.components = [[NSCalendar currentCalendar]
428 | components:NSCalendarUnitWeekday | NSCalendarUnitMonth | NSCalendarUnitYear
429 | fromDate:self.date];
430 |
431 | [self setupViews];
432 |
433 | [self layoutIfNeeded];
434 | }
435 |
436 | - (NSDate *)dateForFirstDayInSection:(NSInteger)section {
437 | // Month start from five years ago
438 | section = section - 60;
439 |
440 | NSDate *now = [_calendar dateFromComponents:[_calendar components:NSCalendarUnitYear|NSCalendarUnitMonth
441 | fromDate:[NSDate date]]];
442 |
443 | NSDateComponents *components = [NSDateComponents new];
444 | components.month = 0;
445 |
446 | CXDurationPickerDate pickerDate = [CXDurationPickerUtils pickerDateFromDate:[self.calendar dateByAddingComponents:components toDate:now options:0]];
447 |
448 | NSDateComponents *dateComponents = [NSDateComponents new];
449 | dateComponents.month = section;
450 |
451 | NSDate *sectionDate = [_calendar dateByAddingComponents:dateComponents toDate:[CXDurationPickerUtils dateFromPickerDate:pickerDate] options:0];
452 |
453 | return sectionDate;
454 | }
455 |
456 | - (NSString *)monthNameFromDate:(NSDate *)date {
457 | NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
458 |
459 | // Must use yyyy not YYYY
460 | //
461 | // Explanation...
462 | // YYYY means year of week
463 | // yyyy means ordinary calendar year
464 | //
465 | // Case in point: 2016/01/01 using YYYY
466 | // US region considers this week to be in 2016
467 | // UK region considers this week to be in 2015
468 | // As a result the calendar would display January 2015 incorrectly
469 | // The reason is straddling days. Some regions say that there must be a minimum number of
470 | // days straddling a week in the new year to be considered the first week of that new year
471 | [dateFormatter setDateFormat:@"MMMM yyyy"];
472 |
473 | NSString *stringFromDate = [dateFormatter stringFromDate:date];
474 |
475 | return stringFromDate;
476 | }
477 |
478 | - (int)numberOfWeekRowsNeeded
479 | {
480 | int colIndex = (int)self.components.weekday - 1; // starting weekday column
481 | int rowIndex = 4; // All months have 4 weeks / 28 days
482 |
483 | for (int i = 28; i < self.numDays; i++) {
484 | colIndex++;
485 | if (colIndex % 7 == 0) {
486 | colIndex = 0;
487 | rowIndex++;
488 | }
489 | }
490 | return colIndex == 0 ? rowIndex : rowIndex+1;
491 | }
492 |
493 | - (CXDurationPickerMonth)monthPickerDateFromDate:(NSDate *)date {
494 | NSCalendar *calendar = [NSCalendar currentCalendar];
495 |
496 | NSDateComponents *components = [calendar
497 | components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
498 | fromDate:date];
499 |
500 | return (CXDurationPickerMonth) {
501 | components.year,
502 | components.month
503 | };
504 | }
505 |
506 | #pragma mark - Colors
507 |
508 | - (void)setDayLabelsToColor:(UIColor *)color {
509 | for (int i = 0; i < 7; i++) {
510 | NSUInteger tag = 100 + i;
511 |
512 | UIView *view = [self viewWithTag:tag];
513 |
514 | if ([view isKindOfClass:[UILabel class]]) {
515 | UILabel *dayLabel = (UILabel *) view;
516 |
517 | [dayLabel setTextColor:self.dayLabelColor];
518 |
519 | [dayLabel setNeedsDisplay];
520 | }
521 | }
522 | }
523 |
524 | - (void)setDaysToColor:(UIColor *)color forKey:(NSString *)key {
525 | for (int i = 0; i < self.numDays; i++) {
526 | NSUInteger tag = 200 + i;
527 |
528 | UIView *view = [self viewWithTag:tag];
529 |
530 | if ([view isKindOfClass:[CXDurationPickerDayView class]]) {
531 | CXDurationPickerDayView *dayView = (CXDurationPickerDayView *) view;
532 |
533 | [dayView setValue:color forKey:key];
534 |
535 | [dayView setNeedsDisplay];
536 | }
537 | }
538 | }
539 |
540 | // Month-specific colors
541 | //
542 | - (void)setDayLabelColor:(UIColor *)color {
543 | _dayLabelColor = color;
544 | [self setDayLabelsToColor:_dayLabelColor];
545 | }
546 |
547 | // Day-specific colors
548 | //
549 | - (void)setDayBackgroundColor:(UIColor *)color {
550 | _dayBackgroundColor = color;
551 | [self setDaysToColor:_dayBackgroundColor forKey:@"dayBackgroundColor"];
552 | }
553 |
554 | - (void)setDayForegroundColor:(UIColor *)color {
555 | _dayForegroundColor = color;
556 | [self setDaysToColor:_dayForegroundColor forKey:@"dayForegroundColor"];
557 | }
558 |
559 | - (void)setDisabledDayBackgroundColor:(UIColor *)color {
560 | _disabledDayBackgroundColor = color;
561 | [self setDaysToColor:_disabledDayBackgroundColor forKey:@"disabledDayBackgroundColor"];
562 | }
563 |
564 | - (void)setDisabledDayForegroundColor:(UIColor *)color {
565 | _disabledDayBackgroundColor = color;
566 | [self setDaysToColor:_disabledDayBackgroundColor forKey:@"disabledDayForegroundColor"];
567 | }
568 |
569 | - (void)setGridColor:(UIColor *)color {
570 | _gridColor = color;
571 | [self setDaysToColor:_gridColor forKey:@"gridColor"];
572 | }
573 |
574 | - (void)setMonthLabelColor:(UIColor *)color {
575 | _monthLabelColor = color;
576 | [self.dateLabel setTextColor:self.monthLabelColor];
577 | }
578 |
579 | - (void)setTerminalBackgroundColor:(UIColor *)color {
580 | _terminalBackgroundColor = color;
581 | [self setDaysToColor:_terminalBackgroundColor forKey:@"terminalBackgroundColor"];
582 | }
583 |
584 | - (void)setTerminalForegroundColor:(UIColor *)color {
585 | _terminalForegroundColor = color;
586 | [self setDaysToColor:_terminalForegroundColor forKey:@"terminalForegroundColor"];
587 | }
588 |
589 | - (void)setTodayBackgroundColor:(UIColor *)color {
590 | _todayBackgroundColor = color;
591 | [self setDaysToColor:_todayBackgroundColor forKey:@"todayBackgroundColor"];
592 | }
593 |
594 | - (void)setTodayForegroundColor:(UIColor *)color {
595 | _todayForegroundColor = color;
596 | [self setDaysToColor:_todayForegroundColor forKey:@"todayForegroundColor"];
597 | }
598 |
599 | - (void)setTransitBackgroundColor:(UIColor *)color {
600 | _transitBackgroundColor = color;
601 | [self setDaysToColor:_transitBackgroundColor forKey:@"transitBackgroundColor"];
602 | }
603 |
604 | - (void)setTransitForegroundColor:(UIColor *)color {
605 | _transitForegroundColor = color;
606 | [self setDaysToColor:_transitForegroundColor forKey:@"transitForegroundColor"];
607 | }
608 |
609 | @end
610 |
--------------------------------------------------------------------------------
/CXDurationPickerDemo/CXDurationPickerDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 01987DE31AAD5097006F012F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987DE21AAD5097006F012F /* main.m */; };
11 | 01987DE61AAD5097006F012F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987DE51AAD5097006F012F /* AppDelegate.m */; };
12 | 01987DE91AAD5097006F012F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987DE81AAD5097006F012F /* ViewController.m */; };
13 | 01987DEC1AAD5097006F012F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01987DEA1AAD5097006F012F /* Main.storyboard */; };
14 | 01987DEE1AAD5097006F012F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 01987DED1AAD5097006F012F /* Images.xcassets */; };
15 | 01987DF11AAD5097006F012F /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01987DEF1AAD5097006F012F /* LaunchScreen.xib */; };
16 | 01987DFD1AAD5097006F012F /* CXDurationPickerDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987DFC1AAD5097006F012F /* CXDurationPickerDemoTests.m */; };
17 | 01987E101AAD550C006F012F /* CXDurationPickerDayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987E091AAD550C006F012F /* CXDurationPickerDayView.m */; };
18 | 01987E111AAD550C006F012F /* CXDurationPickerMonthView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987E0B1AAD550C006F012F /* CXDurationPickerMonthView.m */; };
19 | 01987E121AAD550C006F012F /* CXDurationPickerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987E0D1AAD550C006F012F /* CXDurationPickerUtils.m */; };
20 | 01987E131AAD550C006F012F /* CXDurationPickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01987E0F1AAD550C006F012F /* CXDurationPickerView.m */; };
21 | 0CCFD7F4A311EA1315BA10F1 /* libPods-CXDurationPickerDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B7CD12B693DC5CCBD5F886EF /* libPods-CXDurationPickerDemo.a */; };
22 | D63813AD1C72270B006C09A8 /* UIColor+CXDurationDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = D63813AC1C72270B006C09A8 /* UIColor+CXDurationDefaults.m */; };
23 | /* End PBXBuildFile section */
24 |
25 | /* Begin PBXContainerItemProxy section */
26 | 01987DF71AAD5097006F012F /* PBXContainerItemProxy */ = {
27 | isa = PBXContainerItemProxy;
28 | containerPortal = 01987DD51AAD5097006F012F /* Project object */;
29 | proxyType = 1;
30 | remoteGlobalIDString = 01987DDC1AAD5097006F012F;
31 | remoteInfo = CXDurationPickerDemo;
32 | };
33 | /* End PBXContainerItemProxy section */
34 |
35 | /* Begin PBXFileReference section */
36 | 01987DDD1AAD5097006F012F /* CXDurationPickerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CXDurationPickerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
37 | 01987DE11AAD5097006F012F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
38 | 01987DE21AAD5097006F012F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
39 | 01987DE41AAD5097006F012F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
40 | 01987DE51AAD5097006F012F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
41 | 01987DE71AAD5097006F012F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
42 | 01987DE81AAD5097006F012F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
43 | 01987DEB1AAD5097006F012F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
44 | 01987DED1AAD5097006F012F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
45 | 01987DF01AAD5097006F012F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
46 | 01987DF61AAD5097006F012F /* CXDurationPickerDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CXDurationPickerDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
47 | 01987DFB1AAD5097006F012F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
48 | 01987DFC1AAD5097006F012F /* CXDurationPickerDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CXDurationPickerDemoTests.m; sourceTree = ""; };
49 | 01987E071AAD550C006F012F /* CXDurationPickerDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CXDurationPickerDate.h; path = ../../CXDurationPicker/CXDurationPickerDate.h; sourceTree = ""; };
50 | 01987E081AAD550C006F012F /* CXDurationPickerDayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CXDurationPickerDayView.h; path = ../../CXDurationPicker/CXDurationPickerDayView.h; sourceTree = ""; };
51 | 01987E091AAD550C006F012F /* CXDurationPickerDayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CXDurationPickerDayView.m; path = ../../CXDurationPicker/CXDurationPickerDayView.m; sourceTree = ""; };
52 | 01987E0A1AAD550C006F012F /* CXDurationPickerMonthView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CXDurationPickerMonthView.h; path = ../../CXDurationPicker/CXDurationPickerMonthView.h; sourceTree = ""; };
53 | 01987E0B1AAD550C006F012F /* CXDurationPickerMonthView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CXDurationPickerMonthView.m; path = ../../CXDurationPicker/CXDurationPickerMonthView.m; sourceTree = ""; };
54 | 01987E0C1AAD550C006F012F /* CXDurationPickerUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CXDurationPickerUtils.h; path = ../../CXDurationPicker/CXDurationPickerUtils.h; sourceTree = ""; };
55 | 01987E0D1AAD550C006F012F /* CXDurationPickerUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CXDurationPickerUtils.m; path = ../../CXDurationPicker/CXDurationPickerUtils.m; sourceTree = ""; };
56 | 01987E0E1AAD550C006F012F /* CXDurationPickerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CXDurationPickerView.h; path = ../../CXDurationPicker/CXDurationPickerView.h; sourceTree = ""; };
57 | 01987E0F1AAD550C006F012F /* CXDurationPickerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CXDurationPickerView.m; path = ../../CXDurationPicker/CXDurationPickerView.m; sourceTree = ""; };
58 | 42E9336D6E9B544FD5CDDDE0 /* Pods-CXDurationPickerDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CXDurationPickerDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CXDurationPickerDemo/Pods-CXDurationPickerDemo.debug.xcconfig"; sourceTree = ""; };
59 | 85E43D292B7B55B586BE704B /* Pods-CXDurationPickerDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CXDurationPickerDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-CXDurationPickerDemo/Pods-CXDurationPickerDemo.release.xcconfig"; sourceTree = ""; };
60 | 91818EB62720CF7386DD2D5F /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
61 | B7CD12B693DC5CCBD5F886EF /* libPods-CXDurationPickerDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CXDurationPickerDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
62 | D63813AB1C72270B006C09A8 /* UIColor+CXDurationDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIColor+CXDurationDefaults.h"; path = "../../CXDurationPicker/UIColor+CXDurationDefaults.h"; sourceTree = ""; };
63 | D63813AC1C72270B006C09A8 /* UIColor+CXDurationDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIColor+CXDurationDefaults.m"; path = "../../CXDurationPicker/UIColor+CXDurationDefaults.m"; sourceTree = ""; };
64 | /* End PBXFileReference section */
65 |
66 | /* Begin PBXFrameworksBuildPhase section */
67 | 01987DDA1AAD5097006F012F /* Frameworks */ = {
68 | isa = PBXFrameworksBuildPhase;
69 | buildActionMask = 2147483647;
70 | files = (
71 | 0CCFD7F4A311EA1315BA10F1 /* libPods-CXDurationPickerDemo.a in Frameworks */,
72 | );
73 | runOnlyForDeploymentPostprocessing = 0;
74 | };
75 | 01987DF31AAD5097006F012F /* Frameworks */ = {
76 | isa = PBXFrameworksBuildPhase;
77 | buildActionMask = 2147483647;
78 | files = (
79 | );
80 | runOnlyForDeploymentPostprocessing = 0;
81 | };
82 | /* End PBXFrameworksBuildPhase section */
83 |
84 | /* Begin PBXGroup section */
85 | 01987DD41AAD5097006F012F = {
86 | isa = PBXGroup;
87 | children = (
88 | 01987DDF1AAD5097006F012F /* CXDurationPickerDemo */,
89 | 01987DF91AAD5097006F012F /* CXDurationPickerDemoTests */,
90 | 01987DDE1AAD5097006F012F /* Products */,
91 | 8176A4D6B36960B6CCFFEFEA /* Pods */,
92 | 8A3B0F907772E530D4005195 /* Frameworks */,
93 | );
94 | sourceTree = "";
95 | };
96 | 01987DDE1AAD5097006F012F /* Products */ = {
97 | isa = PBXGroup;
98 | children = (
99 | 01987DDD1AAD5097006F012F /* CXDurationPickerDemo.app */,
100 | 01987DF61AAD5097006F012F /* CXDurationPickerDemoTests.xctest */,
101 | );
102 | name = Products;
103 | sourceTree = "";
104 | };
105 | 01987DDF1AAD5097006F012F /* CXDurationPickerDemo */ = {
106 | isa = PBXGroup;
107 | children = (
108 | 01987E061AAD54F7006F012F /* CXDurationPicker */,
109 | 01987DE41AAD5097006F012F /* AppDelegate.h */,
110 | 01987DE51AAD5097006F012F /* AppDelegate.m */,
111 | 01987DE71AAD5097006F012F /* ViewController.h */,
112 | 01987DE81AAD5097006F012F /* ViewController.m */,
113 | 01987DEA1AAD5097006F012F /* Main.storyboard */,
114 | 01987DED1AAD5097006F012F /* Images.xcassets */,
115 | 01987DEF1AAD5097006F012F /* LaunchScreen.xib */,
116 | 01987DE01AAD5097006F012F /* Supporting Files */,
117 | );
118 | path = CXDurationPickerDemo;
119 | sourceTree = "";
120 | };
121 | 01987DE01AAD5097006F012F /* Supporting Files */ = {
122 | isa = PBXGroup;
123 | children = (
124 | 01987DE11AAD5097006F012F /* Info.plist */,
125 | 01987DE21AAD5097006F012F /* main.m */,
126 | );
127 | name = "Supporting Files";
128 | sourceTree = "";
129 | };
130 | 01987DF91AAD5097006F012F /* CXDurationPickerDemoTests */ = {
131 | isa = PBXGroup;
132 | children = (
133 | 01987DFC1AAD5097006F012F /* CXDurationPickerDemoTests.m */,
134 | 01987DFA1AAD5097006F012F /* Supporting Files */,
135 | );
136 | path = CXDurationPickerDemoTests;
137 | sourceTree = "";
138 | };
139 | 01987DFA1AAD5097006F012F /* Supporting Files */ = {
140 | isa = PBXGroup;
141 | children = (
142 | 01987DFB1AAD5097006F012F /* Info.plist */,
143 | );
144 | name = "Supporting Files";
145 | sourceTree = "";
146 | };
147 | 01987E061AAD54F7006F012F /* CXDurationPicker */ = {
148 | isa = PBXGroup;
149 | children = (
150 | 01987E071AAD550C006F012F /* CXDurationPickerDate.h */,
151 | 01987E081AAD550C006F012F /* CXDurationPickerDayView.h */,
152 | 01987E091AAD550C006F012F /* CXDurationPickerDayView.m */,
153 | 01987E0A1AAD550C006F012F /* CXDurationPickerMonthView.h */,
154 | 01987E0B1AAD550C006F012F /* CXDurationPickerMonthView.m */,
155 | 01987E0C1AAD550C006F012F /* CXDurationPickerUtils.h */,
156 | 01987E0D1AAD550C006F012F /* CXDurationPickerUtils.m */,
157 | 01987E0E1AAD550C006F012F /* CXDurationPickerView.h */,
158 | 01987E0F1AAD550C006F012F /* CXDurationPickerView.m */,
159 | D63813AB1C72270B006C09A8 /* UIColor+CXDurationDefaults.h */,
160 | D63813AC1C72270B006C09A8 /* UIColor+CXDurationDefaults.m */,
161 | );
162 | name = CXDurationPicker;
163 | sourceTree = "";
164 | };
165 | 8176A4D6B36960B6CCFFEFEA /* Pods */ = {
166 | isa = PBXGroup;
167 | children = (
168 | 42E9336D6E9B544FD5CDDDE0 /* Pods-CXDurationPickerDemo.debug.xcconfig */,
169 | 85E43D292B7B55B586BE704B /* Pods-CXDurationPickerDemo.release.xcconfig */,
170 | );
171 | name = Pods;
172 | sourceTree = "";
173 | };
174 | 8A3B0F907772E530D4005195 /* Frameworks */ = {
175 | isa = PBXGroup;
176 | children = (
177 | B7CD12B693DC5CCBD5F886EF /* libPods-CXDurationPickerDemo.a */,
178 | 91818EB62720CF7386DD2D5F /* libPods.a */,
179 | );
180 | name = Frameworks;
181 | sourceTree = "";
182 | };
183 | /* End PBXGroup section */
184 |
185 | /* Begin PBXNativeTarget section */
186 | 01987DDC1AAD5097006F012F /* CXDurationPickerDemo */ = {
187 | isa = PBXNativeTarget;
188 | buildConfigurationList = 01987E001AAD5097006F012F /* Build configuration list for PBXNativeTarget "CXDurationPickerDemo" */;
189 | buildPhases = (
190 | 59FAFE43FBCA9E96BECA5849 /* Check Pods Manifest.lock */,
191 | 01987DD91AAD5097006F012F /* Sources */,
192 | 01987DDA1AAD5097006F012F /* Frameworks */,
193 | 01987DDB1AAD5097006F012F /* Resources */,
194 | DC6FD7D1121C38DF0CB8313F /* Copy Pods Resources */,
195 | F9802359F8ACD1E3FA860FCE /* Embed Pods Frameworks */,
196 | );
197 | buildRules = (
198 | );
199 | dependencies = (
200 | );
201 | name = CXDurationPickerDemo;
202 | productName = CXDurationPickerDemo;
203 | productReference = 01987DDD1AAD5097006F012F /* CXDurationPickerDemo.app */;
204 | productType = "com.apple.product-type.application";
205 | };
206 | 01987DF51AAD5097006F012F /* CXDurationPickerDemoTests */ = {
207 | isa = PBXNativeTarget;
208 | buildConfigurationList = 01987E031AAD5097006F012F /* Build configuration list for PBXNativeTarget "CXDurationPickerDemoTests" */;
209 | buildPhases = (
210 | 01987DF21AAD5097006F012F /* Sources */,
211 | 01987DF31AAD5097006F012F /* Frameworks */,
212 | 01987DF41AAD5097006F012F /* Resources */,
213 | );
214 | buildRules = (
215 | );
216 | dependencies = (
217 | 01987DF81AAD5097006F012F /* PBXTargetDependency */,
218 | );
219 | name = CXDurationPickerDemoTests;
220 | productName = CXDurationPickerDemoTests;
221 | productReference = 01987DF61AAD5097006F012F /* CXDurationPickerDemoTests.xctest */;
222 | productType = "com.apple.product-type.bundle.unit-test";
223 | };
224 | /* End PBXNativeTarget section */
225 |
226 | /* Begin PBXProject section */
227 | 01987DD51AAD5097006F012F /* Project object */ = {
228 | isa = PBXProject;
229 | attributes = {
230 | LastUpgradeCheck = 0610;
231 | ORGANIZATIONNAME = "Concur Labs";
232 | TargetAttributes = {
233 | 01987DDC1AAD5097006F012F = {
234 | CreatedOnToolsVersion = 6.1.1;
235 | DevelopmentTeam = C2UZCAZ8FK;
236 | };
237 | 01987DF51AAD5097006F012F = {
238 | CreatedOnToolsVersion = 6.1.1;
239 | TestTargetID = 01987DDC1AAD5097006F012F;
240 | };
241 | };
242 | };
243 | buildConfigurationList = 01987DD81AAD5097006F012F /* Build configuration list for PBXProject "CXDurationPickerDemo" */;
244 | compatibilityVersion = "Xcode 3.2";
245 | developmentRegion = English;
246 | hasScannedForEncodings = 0;
247 | knownRegions = (
248 | en,
249 | Base,
250 | );
251 | mainGroup = 01987DD41AAD5097006F012F;
252 | productRefGroup = 01987DDE1AAD5097006F012F /* Products */;
253 | projectDirPath = "";
254 | projectRoot = "";
255 | targets = (
256 | 01987DDC1AAD5097006F012F /* CXDurationPickerDemo */,
257 | 01987DF51AAD5097006F012F /* CXDurationPickerDemoTests */,
258 | );
259 | };
260 | /* End PBXProject section */
261 |
262 | /* Begin PBXResourcesBuildPhase section */
263 | 01987DDB1AAD5097006F012F /* Resources */ = {
264 | isa = PBXResourcesBuildPhase;
265 | buildActionMask = 2147483647;
266 | files = (
267 | 01987DEC1AAD5097006F012F /* Main.storyboard in Resources */,
268 | 01987DF11AAD5097006F012F /* LaunchScreen.xib in Resources */,
269 | 01987DEE1AAD5097006F012F /* Images.xcassets in Resources */,
270 | );
271 | runOnlyForDeploymentPostprocessing = 0;
272 | };
273 | 01987DF41AAD5097006F012F /* Resources */ = {
274 | isa = PBXResourcesBuildPhase;
275 | buildActionMask = 2147483647;
276 | files = (
277 | );
278 | runOnlyForDeploymentPostprocessing = 0;
279 | };
280 | /* End PBXResourcesBuildPhase section */
281 |
282 | /* Begin PBXShellScriptBuildPhase section */
283 | 59FAFE43FBCA9E96BECA5849 /* Check Pods Manifest.lock */ = {
284 | isa = PBXShellScriptBuildPhase;
285 | buildActionMask = 2147483647;
286 | files = (
287 | );
288 | inputPaths = (
289 | );
290 | name = "Check Pods Manifest.lock";
291 | outputPaths = (
292 | );
293 | runOnlyForDeploymentPostprocessing = 0;
294 | shellPath = /bin/sh;
295 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
296 | showEnvVarsInLog = 0;
297 | };
298 | DC6FD7D1121C38DF0CB8313F /* Copy Pods Resources */ = {
299 | isa = PBXShellScriptBuildPhase;
300 | buildActionMask = 2147483647;
301 | files = (
302 | );
303 | inputPaths = (
304 | );
305 | name = "Copy Pods Resources";
306 | outputPaths = (
307 | );
308 | runOnlyForDeploymentPostprocessing = 0;
309 | shellPath = /bin/sh;
310 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CXDurationPickerDemo/Pods-CXDurationPickerDemo-resources.sh\"\n";
311 | showEnvVarsInLog = 0;
312 | };
313 | F9802359F8ACD1E3FA860FCE /* Embed Pods Frameworks */ = {
314 | isa = PBXShellScriptBuildPhase;
315 | buildActionMask = 2147483647;
316 | files = (
317 | );
318 | inputPaths = (
319 | );
320 | name = "Embed Pods Frameworks";
321 | outputPaths = (
322 | );
323 | runOnlyForDeploymentPostprocessing = 0;
324 | shellPath = /bin/sh;
325 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CXDurationPickerDemo/Pods-CXDurationPickerDemo-frameworks.sh\"\n";
326 | showEnvVarsInLog = 0;
327 | };
328 | /* End PBXShellScriptBuildPhase section */
329 |
330 | /* Begin PBXSourcesBuildPhase section */
331 | 01987DD91AAD5097006F012F /* Sources */ = {
332 | isa = PBXSourcesBuildPhase;
333 | buildActionMask = 2147483647;
334 | files = (
335 | D63813AD1C72270B006C09A8 /* UIColor+CXDurationDefaults.m in Sources */,
336 | 01987E121AAD550C006F012F /* CXDurationPickerUtils.m in Sources */,
337 | 01987E101AAD550C006F012F /* CXDurationPickerDayView.m in Sources */,
338 | 01987DE91AAD5097006F012F /* ViewController.m in Sources */,
339 | 01987DE61AAD5097006F012F /* AppDelegate.m in Sources */,
340 | 01987E111AAD550C006F012F /* CXDurationPickerMonthView.m in Sources */,
341 | 01987E131AAD550C006F012F /* CXDurationPickerView.m in Sources */,
342 | 01987DE31AAD5097006F012F /* main.m in Sources */,
343 | );
344 | runOnlyForDeploymentPostprocessing = 0;
345 | };
346 | 01987DF21AAD5097006F012F /* Sources */ = {
347 | isa = PBXSourcesBuildPhase;
348 | buildActionMask = 2147483647;
349 | files = (
350 | 01987DFD1AAD5097006F012F /* CXDurationPickerDemoTests.m in Sources */,
351 | );
352 | runOnlyForDeploymentPostprocessing = 0;
353 | };
354 | /* End PBXSourcesBuildPhase section */
355 |
356 | /* Begin PBXTargetDependency section */
357 | 01987DF81AAD5097006F012F /* PBXTargetDependency */ = {
358 | isa = PBXTargetDependency;
359 | target = 01987DDC1AAD5097006F012F /* CXDurationPickerDemo */;
360 | targetProxy = 01987DF71AAD5097006F012F /* PBXContainerItemProxy */;
361 | };
362 | /* End PBXTargetDependency section */
363 |
364 | /* Begin PBXVariantGroup section */
365 | 01987DEA1AAD5097006F012F /* Main.storyboard */ = {
366 | isa = PBXVariantGroup;
367 | children = (
368 | 01987DEB1AAD5097006F012F /* Base */,
369 | );
370 | name = Main.storyboard;
371 | sourceTree = "";
372 | };
373 | 01987DEF1AAD5097006F012F /* LaunchScreen.xib */ = {
374 | isa = PBXVariantGroup;
375 | children = (
376 | 01987DF01AAD5097006F012F /* Base */,
377 | );
378 | name = LaunchScreen.xib;
379 | sourceTree = "";
380 | };
381 | /* End PBXVariantGroup section */
382 |
383 | /* Begin XCBuildConfiguration section */
384 | 01987DFE1AAD5097006F012F /* Debug */ = {
385 | isa = XCBuildConfiguration;
386 | buildSettings = {
387 | ALWAYS_SEARCH_USER_PATHS = NO;
388 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
389 | CLANG_CXX_LIBRARY = "libc++";
390 | CLANG_ENABLE_MODULES = YES;
391 | CLANG_ENABLE_OBJC_ARC = YES;
392 | CLANG_WARN_BOOL_CONVERSION = YES;
393 | CLANG_WARN_CONSTANT_CONVERSION = YES;
394 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
395 | CLANG_WARN_EMPTY_BODY = YES;
396 | CLANG_WARN_ENUM_CONVERSION = YES;
397 | CLANG_WARN_INT_CONVERSION = YES;
398 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
399 | CLANG_WARN_UNREACHABLE_CODE = YES;
400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
401 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
402 | COPY_PHASE_STRIP = NO;
403 | ENABLE_STRICT_OBJC_MSGSEND = YES;
404 | GCC_C_LANGUAGE_STANDARD = gnu99;
405 | GCC_DYNAMIC_NO_PIC = NO;
406 | GCC_OPTIMIZATION_LEVEL = 0;
407 | GCC_PREPROCESSOR_DEFINITIONS = (
408 | "DEBUG=1",
409 | "$(inherited)",
410 | );
411 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
412 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
413 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
414 | GCC_WARN_UNDECLARED_SELECTOR = YES;
415 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
416 | GCC_WARN_UNUSED_FUNCTION = YES;
417 | GCC_WARN_UNUSED_VARIABLE = YES;
418 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
419 | MTL_ENABLE_DEBUG_INFO = YES;
420 | ONLY_ACTIVE_ARCH = YES;
421 | SDKROOT = iphoneos;
422 | TARGETED_DEVICE_FAMILY = "1,2";
423 | };
424 | name = Debug;
425 | };
426 | 01987DFF1AAD5097006F012F /* Release */ = {
427 | isa = XCBuildConfiguration;
428 | buildSettings = {
429 | ALWAYS_SEARCH_USER_PATHS = NO;
430 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
431 | CLANG_CXX_LIBRARY = "libc++";
432 | CLANG_ENABLE_MODULES = YES;
433 | CLANG_ENABLE_OBJC_ARC = YES;
434 | CLANG_WARN_BOOL_CONVERSION = YES;
435 | CLANG_WARN_CONSTANT_CONVERSION = YES;
436 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
437 | CLANG_WARN_EMPTY_BODY = YES;
438 | CLANG_WARN_ENUM_CONVERSION = YES;
439 | CLANG_WARN_INT_CONVERSION = YES;
440 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
441 | CLANG_WARN_UNREACHABLE_CODE = YES;
442 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
443 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
444 | COPY_PHASE_STRIP = YES;
445 | ENABLE_NS_ASSERTIONS = NO;
446 | ENABLE_STRICT_OBJC_MSGSEND = YES;
447 | GCC_C_LANGUAGE_STANDARD = gnu99;
448 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
449 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
450 | GCC_WARN_UNDECLARED_SELECTOR = YES;
451 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
452 | GCC_WARN_UNUSED_FUNCTION = YES;
453 | GCC_WARN_UNUSED_VARIABLE = YES;
454 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
455 | MTL_ENABLE_DEBUG_INFO = NO;
456 | SDKROOT = iphoneos;
457 | TARGETED_DEVICE_FAMILY = "1,2";
458 | VALIDATE_PRODUCT = YES;
459 | };
460 | name = Release;
461 | };
462 | 01987E011AAD5097006F012F /* Debug */ = {
463 | isa = XCBuildConfiguration;
464 | baseConfigurationReference = 42E9336D6E9B544FD5CDDDE0 /* Pods-CXDurationPickerDemo.debug.xcconfig */;
465 | buildSettings = {
466 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
467 | DEVELOPMENT_TEAM = C2UZCAZ8FK;
468 | GCC_GENERATE_TEST_COVERAGE_FILES = YES;
469 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
470 | INFOPLIST_FILE = CXDurationPickerDemo/Info.plist;
471 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
472 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
473 | PRODUCT_NAME = "$(TARGET_NAME)";
474 | };
475 | name = Debug;
476 | };
477 | 01987E021AAD5097006F012F /* Release */ = {
478 | isa = XCBuildConfiguration;
479 | baseConfigurationReference = 85E43D292B7B55B586BE704B /* Pods-CXDurationPickerDemo.release.xcconfig */;
480 | buildSettings = {
481 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
482 | DEVELOPMENT_TEAM = C2UZCAZ8FK;
483 | GCC_GENERATE_TEST_COVERAGE_FILES = YES;
484 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
485 | INFOPLIST_FILE = CXDurationPickerDemo/Info.plist;
486 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
487 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
488 | PRODUCT_NAME = "$(TARGET_NAME)";
489 | };
490 | name = Release;
491 | };
492 | 01987E041AAD5097006F012F /* Debug */ = {
493 | isa = XCBuildConfiguration;
494 | buildSettings = {
495 | BUNDLE_LOADER = "$(TEST_HOST)";
496 | FRAMEWORK_SEARCH_PATHS = (
497 | "$(SDKROOT)/Developer/Library/Frameworks",
498 | "$(inherited)",
499 | );
500 | GCC_GENERATE_TEST_COVERAGE_FILES = YES;
501 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
502 | GCC_PREPROCESSOR_DEFINITIONS = (
503 | "DEBUG=1",
504 | "$(inherited)",
505 | );
506 | INFOPLIST_FILE = CXDurationPickerDemoTests/Info.plist;
507 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
508 | PRODUCT_NAME = "$(TARGET_NAME)";
509 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CXDurationPickerDemo.app/CXDurationPickerDemo";
510 | };
511 | name = Debug;
512 | };
513 | 01987E051AAD5097006F012F /* Release */ = {
514 | isa = XCBuildConfiguration;
515 | buildSettings = {
516 | BUNDLE_LOADER = "$(TEST_HOST)";
517 | FRAMEWORK_SEARCH_PATHS = (
518 | "$(SDKROOT)/Developer/Library/Frameworks",
519 | "$(inherited)",
520 | );
521 | GCC_GENERATE_TEST_COVERAGE_FILES = YES;
522 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
523 | INFOPLIST_FILE = CXDurationPickerDemoTests/Info.plist;
524 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
525 | PRODUCT_NAME = "$(TARGET_NAME)";
526 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CXDurationPickerDemo.app/CXDurationPickerDemo";
527 | };
528 | name = Release;
529 | };
530 | /* End XCBuildConfiguration section */
531 |
532 | /* Begin XCConfigurationList section */
533 | 01987DD81AAD5097006F012F /* Build configuration list for PBXProject "CXDurationPickerDemo" */ = {
534 | isa = XCConfigurationList;
535 | buildConfigurations = (
536 | 01987DFE1AAD5097006F012F /* Debug */,
537 | 01987DFF1AAD5097006F012F /* Release */,
538 | );
539 | defaultConfigurationIsVisible = 0;
540 | defaultConfigurationName = Release;
541 | };
542 | 01987E001AAD5097006F012F /* Build configuration list for PBXNativeTarget "CXDurationPickerDemo" */ = {
543 | isa = XCConfigurationList;
544 | buildConfigurations = (
545 | 01987E011AAD5097006F012F /* Debug */,
546 | 01987E021AAD5097006F012F /* Release */,
547 | );
548 | defaultConfigurationIsVisible = 0;
549 | defaultConfigurationName = Release;
550 | };
551 | 01987E031AAD5097006F012F /* Build configuration list for PBXNativeTarget "CXDurationPickerDemoTests" */ = {
552 | isa = XCConfigurationList;
553 | buildConfigurations = (
554 | 01987E041AAD5097006F012F /* Debug */,
555 | 01987E051AAD5097006F012F /* Release */,
556 | );
557 | defaultConfigurationIsVisible = 0;
558 | defaultConfigurationName = Release;
559 | };
560 | /* End XCConfigurationList section */
561 | };
562 | rootObject = 01987DD51AAD5097006F012F /* Project object */;
563 | }
564 |
--------------------------------------------------------------------------------
/CXDurationPicker/CXDurationPickerView.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Concur Technologies
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #import "CXDurationPickerDayView.h"
18 | #import "CXDurationPickerMonthView.h"
19 | #import "CXDurationPickerView.h"
20 | #import "CXDurationPickerUtils.h"
21 | #import "UIColor+CXDurationDefaults.h"
22 |
23 | #define defaultTodayColor [UIColor colorWithRed:0.1f green:0.004f blue:0.3f alpha:0.3f]
24 |
25 | @interface CXDurationPickerView ()
26 |
27 | @property (strong, nonatomic) NSCalendar *calendar;
28 | @property (strong, nonatomic) UITableView *table;
29 | @property (strong, nonatomic) NSMutableArray *monthViews;
30 | @property (strong, nonatomic) NSMutableArray *days;
31 |
32 | @end
33 |
34 | @implementation CXDurationPickerView
35 |
36 | #pragma mark - Lifecycle
37 |
38 | - (void)baseInit {
39 | self.calendar = [NSCalendar currentCalendar];
40 |
41 | self.dayLabelColor = [UIColor defaultDayLabelColor];
42 | self.monthLabelColor = [UIColor defaultMonthLabelColor];
43 |
44 | self.dayBackgroundColor = [UIColor defaultDayBackgroundColor];
45 | self.dayForegroundColor = [UIColor defaultDayForegroundColor];
46 | self.disabledDayBackgroundColor = [UIColor defaultDisabledDayBackgroundColor];
47 | self.disabledDayForegroundColor = [UIColor defaultDisabledDayForegroundColor];
48 | self.gridColor = [UIColor defaultGridColor];
49 | self.terminalBackgroundColor = [UIColor defaultTerminalBackgroundColor];
50 | self.terminalForegroundColor = [UIColor defaultTerminalForegroundColor];
51 | self.todayBackgroundColor = [UIColor defaultTodayBackgroundColor];
52 | self.todayForegroundColor = [UIColor defaultTodayForegroundColor];
53 | self.transitBackgroundColor = [UIColor defaultTransitBackgroundColor];
54 | self.transitForegroundColor = [UIColor defaultTransitForegroundColor];
55 | self.roundedTerminals = YES;
56 | self.allowSelectionsInPast = NO;
57 | self.startDate = (CXDurationPickerDate) { 0, 0, 0 };
58 | self.endDate = (CXDurationPickerDate) { 0, 0, 0 };
59 |
60 | self.monthViews = [[NSMutableArray alloc] init];
61 |
62 | self.table = [[UITableView alloc] initWithFrame:self.bounds];
63 |
64 | [self addSubview:self.table];
65 |
66 | [self.table setDataSource:self];
67 | [self.table setDelegate:self];
68 |
69 | self.table.allowsSelection = NO;
70 | self.table.backgroundColor = [UIColor defaultMonthBackgroundColor];
71 | self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
72 | self.table.showsVerticalScrollIndicator = NO;
73 |
74 | [self addMonths];
75 | }
76 |
77 | - (void)awakeFromNib {
78 | [super awakeFromNib];
79 |
80 | [self baseInit];
81 | }
82 |
83 | - (void)didMoveToWindow {
84 | [super didMoveToWindow];
85 |
86 | [self scrollToStartMonth:NO];
87 | }
88 |
89 | - (id)initWithFrame:(CGRect)frame {
90 | self = [super initWithFrame:frame];
91 |
92 | if (self) {
93 | [self baseInit];
94 | }
95 |
96 | return self;
97 | }
98 |
99 | - (void)layoutSubviews {
100 | [super layoutSubviews];
101 |
102 | [self addMonths];
103 |
104 | self.table.frame = self.bounds;
105 |
106 | [self.table setNeedsLayout];
107 | }
108 |
109 | #pragma mark - UITableViewDataSource
110 |
111 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
112 | return 1;
113 | }
114 |
115 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
116 | // Infinite scroll. Load more months when we're "3" months from the end.
117 | //
118 | #ifndef COMPONENTS_DEMO
119 | if (indexPath.row == [tableView numberOfRowsInSection:0] - 3) {
120 | [self addMonthsAsync];
121 | }
122 | #endif
123 |
124 | UITableViewCell *cell = [tableView
125 | dequeueReusableCellWithIdentifier:@"DurationPickerCell"];
126 |
127 | if (cell == nil) {
128 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DurationPickerCell"];
129 | }
130 |
131 | cell.backgroundColor = [UIColor clearColor];
132 |
133 | UIView *oldMonthView = [[cell.contentView subviews] firstObject];
134 |
135 | if (oldMonthView != nil) {
136 | [oldMonthView removeFromSuperview];
137 | }
138 |
139 | NSInteger row = indexPath.row;
140 |
141 | CXDurationPickerMonthView *v = [self monthViewForRow:row];
142 |
143 | // Tell month view to disable days before today is user has requested it.
144 | //
145 | // The logic here is perhaps unnecessarily confusing...
146 | //
147 | if (self.allowSelectionsInPast == NO) {
148 | v.disableDaysBeforeToday = YES;
149 | if (!self.allowSelectionOfYesterdayAsStartDay) {
150 | v.disableYesterday = YES;
151 | } else {
152 | v.disableYesterday = NO;
153 | }
154 | } else {
155 | v.disableDaysBeforeToday = NO;
156 | v.disableYesterday = NO;
157 | }
158 |
159 | if (self.blockedDays && self.blockedDays.count > 0) {
160 | [v assignBlockedDays:self.blockedDays];
161 | }
162 |
163 | v.roundedTerminals = self.roundedTerminals;
164 |
165 | v.backgroundColor = self.backgroundColor;
166 |
167 | v.dayLabelColor = self.dayLabelColor;
168 | v.monthLabelColor = self.monthLabelColor;
169 |
170 | v.dayBackgroundColor = self.dayBackgroundColor;
171 | v.dayForegroundColor = self.dayForegroundColor;
172 | v.disabledDayBackgroundColor = self.disabledDayBackgroundColor;
173 | v.disabledDayForegroundColor = self.disabledDayForegroundColor;
174 | v.gridColor = self.gridColor;
175 | v.terminalBackgroundColor = self.terminalBackgroundColor;
176 | v.terminalForegroundColor = self.terminalForegroundColor;
177 | v.todayBackgroundColor = self.todayBackgroundColor;
178 | v.todayForegroundColor = self.todayForegroundColor;
179 | v.transitBackgroundColor = self.transitBackgroundColor;
180 | v.transitForegroundColor = self.transitForegroundColor;
181 |
182 | [cell.contentView addSubview:v];
183 |
184 | return cell;
185 | }
186 |
187 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
188 | return [self.monthViews count];
189 | }
190 |
191 | #pragma mark - UITableViewDelegate
192 |
193 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
194 | CXDurationPickerMonthView *view = [self.monthViews objectAtIndex:indexPath.row];
195 |
196 | view.frame = self.bounds;
197 | [view sizeToFit];
198 |
199 | CGFloat cellHeight = view.frame.size.height;
200 |
201 | return cellHeight;
202 | }
203 |
204 | #pragma mark - CXCalendarMonthViewDelegate
205 |
206 | - (void)monthView:(CXDurationPickerMonthView *)view daySelected:(CXDurationPickerDayView *)dayView {
207 |
208 | // Picker should not allow same day selection if flag is set to NO
209 | //
210 | // Duration Mode:
211 | // Did user select a zero-day range?
212 | //
213 | // Single Mode:
214 | // Did user select "today"?
215 | //
216 | if (!self.allowSelectionOnSameDay) {
217 | if (self.mode == CXDurationPickerModeStartDate) {
218 | if ([self isPickerDate:dayView.pickerDate equalTo:_endDate]) {
219 | return;
220 | }
221 | } else if (self.mode == CXDurationPickerModeEndDate) {
222 | if ([self isPickerDate:_startDate equalTo:dayView.pickerDate]) {
223 | return;
224 | }
225 | } else if (self.mode == CXDurationPickerModeSingleDate) {
226 | if ([self isPickerDate:_singleDate equalTo:dayView.pickerDate]) {
227 | return;
228 | }
229 | }
230 | }
231 |
232 | // Did user select a date before "today"? If so, is this allowed?
233 | //
234 | if (self.mode == CXDurationPickerModeStartDate) {
235 | if ([self isPickerDateInPast:dayView.pickerDate]) {
236 | if (!self.allowSelectionsInPast) {
237 | if ([self isPickerDateYesterday:dayView.pickerDate]) {
238 | if (!self.allowSelectionOfYesterdayAsStartDay) {
239 | if ([self.delegate respondsToSelector:@selector(durationPicker:didSelectDateInPast:forMode:)]) {
240 | [self.delegate durationPicker:self didSelectDateInPast:dayView.pickerDate forMode:_mode];
241 | }
242 | return;
243 | }
244 | }
245 | else {
246 | if ([self.delegate respondsToSelector:@selector(durationPicker:didSelectDateInPast:forMode:)]) {
247 | [self.delegate durationPicker:self didSelectDateInPast:dayView.pickerDate forMode:_mode];
248 | }
249 | return;
250 | }
251 | }
252 | }
253 | } else if (self.mode == CXDurationPickerModeEndDate) {
254 | if ([self isPickerDateInPast:dayView.pickerDate]) {
255 | if (!self.allowSelectionsInPast) {
256 | if ([self.delegate respondsToSelector:@selector(durationPicker:didSelectDateInPast:forMode:)]) {
257 | [self.delegate durationPicker:self didSelectDateInPast:dayView.pickerDate forMode:_mode];
258 | }
259 | return;
260 | }
261 | }
262 | } else if (self.mode == CXDurationPickerModeSingleDate) {
263 | if ([self isPickerDateInPast:dayView.pickerDate]) {
264 | if (!self.allowSelectionsInPast) {
265 | if ([self.delegate respondsToSelector:@selector(durationPicker:didSelectDateInPast:forMode:)]) {
266 | [self.delegate durationPicker:self didSelectDateInPast:dayView.pickerDate forMode:_mode];
267 | }
268 | return;
269 | }
270 | }
271 | }
272 |
273 | // Duration Mode:
274 | // If user selected a start date which occurs after current end date, or
275 | // If user selected a end date which occurs before current start date
276 | //
277 | if (self.mode == CXDurationPickerModeStartDate) {
278 | if (![self isDurationValidForStartPickerDate:dayView.pickerDate andEndPickerDate:_endDate]) {
279 | if ([self.delegate respondsToSelector:@selector(durationPicker:invalidStartDateSelected:)]) {
280 | [self.delegate durationPicker:self invalidStartDateSelected:dayView.pickerDate];
281 | }
282 | return;
283 | }
284 | } else if (self.mode == CXDurationPickerModeEndDate) {
285 | if (![self isDurationValidForStartPickerDate:_startDate andEndPickerDate:dayView.pickerDate]) {
286 | if ([self.delegate respondsToSelector:@selector(durationPicker:invalidEndDateSelected:)]) {
287 | [self.delegate durationPicker:self invalidEndDateSelected:dayView.pickerDate];
288 | }
289 | return;
290 | }
291 | }
292 |
293 | // Notify delegate of date changes.
294 | //
295 | if (self.delegate != nil) {
296 | if (self.mode == CXDurationPickerModeStartDate) {
297 | _startDate = dayView.pickerDate;
298 | [self.delegate durationPicker:self startDateChanged:dayView.pickerDate];
299 | } else if (self.mode == CXDurationPickerModeEndDate) {
300 | _endDate = dayView.pickerDate;
301 | [self.delegate durationPicker:self endDateChanged:dayView.pickerDate];
302 | } else if (self.mode == CXDurationPickerModeSingleDate) {
303 | [self changeSingleDateForDayView:dayView];
304 | [self.delegate durationPicker:self singleDateChanged:dayView.pickerDate];
305 | }
306 | }
307 |
308 | // Duration Mode:
309 | // Update the duration.
310 | //
311 | if (self.mode == CXDurationPickerModeStartDate || self.mode == CXDurationPickerModeEndDate) {
312 | [self clearCurrentDuration];
313 | [self createDuration];
314 | }
315 | }
316 |
317 | #pragma mark - Public API
318 |
319 | - (void)scrollToStartMonth:(BOOL)animated {
320 | dispatch_async(dispatch_get_main_queue(), ^{
321 | NSIndexPath *path = nil;
322 | if ([self hasStartDate]) {
323 | path = [self indexPathForPickerDate:self.startDate];
324 | } else {
325 | path = [self indexPathForPickerDate:[self pickerDateForToday]];
326 | }
327 |
328 | if (path) {
329 | [self.table scrollToRowAtIndexPath:path
330 | atScrollPosition:UITableViewScrollPositionTop
331 | animated:animated];
332 | }
333 | });
334 | }
335 |
336 | - (void)scrollToToday:(BOOL)animated {
337 | dispatch_async(dispatch_get_main_queue(), ^{
338 | NSIndexPath *path = [NSIndexPath indexPathForRow:12 inSection:0];
339 |
340 | if (path) {
341 | [self.table scrollToRowAtIndexPath:path
342 | atScrollPosition:UITableViewScrollPositionTop
343 | animated:animated];
344 | }
345 | });
346 | }
347 |
348 | - (void)setEndDate:(CXDurationPickerDate)endDate {
349 | _endDate = endDate;
350 |
351 | [self createDuration];
352 | }
353 |
354 | - (void)setSingleDate:(CXDurationPickerDate)singleDate {
355 | [self clearSingle];
356 |
357 | CXDurationPickerDayView *dayView = [self dayForPickerDate:singleDate];
358 |
359 | [self changeSingleDateForDayView:dayView];
360 | }
361 |
362 | - (void)setStartDate:(CXDurationPickerDate)startDate {
363 | _startDate = startDate;
364 |
365 | [self createDuration];
366 | }
367 |
368 | - (void)setStartDate:(NSDate *)date withDuration:(NSUInteger)days {
369 | CXDurationPickerDate pickerDate = [CXDurationPickerUtils pickerDateFromDate:date];
370 |
371 | [self setStartPickerDate:pickerDate withDuration:days];
372 | }
373 |
374 | - (void)setStartPickerDate:(CXDurationPickerDate)pickerDate withDuration:(NSUInteger)days {
375 | [self clearCurrentDuration];
376 |
377 | _startDate = pickerDate;
378 |
379 | _endDate = [CXDurationPickerUtils pickerDateShiftedByDays:days fromPickerDate:pickerDate];
380 |
381 | [self createDuration];
382 | }
383 |
384 | - (void)setType:(CXDurationPickerType)type {
385 | if (type == CXDurationPickerTypeSingle) {
386 | [self clearCurrentDuration];
387 | self.mode = CXDurationPickerModeSingleDate;
388 | } else {
389 | [self clearSingle];
390 | self.mode = CXDurationPickerModeStartDate;
391 | }
392 |
393 | _type = type;
394 | }
395 |
396 | - (void)shiftDurationToEndPickerDate:(CXDurationPickerDate)pickerDate {
397 | NSError *error;
398 |
399 | [self shiftDurationToEndPickerDate:pickerDate error:&error];
400 | }
401 |
402 | - (void)shiftDurationToStartPickerDate:(CXDurationPickerDate)pickerDate {
403 | NSError *error;
404 |
405 | [self shiftDurationToStartPickerDate:pickerDate error:&error];
406 | }
407 |
408 | - (BOOL)shiftDurationToEndPickerDate:(CXDurationPickerDate)pickerDate error:(NSError **)error {
409 | // Convert picker-dates to NSDates so we easily can do some calcs on them.
410 | //
411 | NSDate *d1 = [CXDurationPickerUtils dateFromPickerDate:self.startDate];
412 | NSDate *d2 = [CXDurationPickerUtils dateFromPickerDate:self.endDate];
413 | NSDate *n1 = [CXDurationPickerUtils dateFromPickerDate:pickerDate];
414 |
415 | // Do not let wrong date selection if there's no end date yet selected
416 | if (d2 == nil) {
417 | return NO;
418 | }
419 | // Calculate number of days in current duration, accounting for days in month.
420 | //
421 | NSDateComponents *diff = [self.calendar
422 | components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
423 | fromDate:d2 toDate:d1 options:0];
424 |
425 | // Calculate new ending date by adding difference.
426 | //
427 | NSDate *n2 = [self.calendar dateByAddingComponents:diff toDate:n1 options:0];
428 |
429 | // Convert back to our convenience model.
430 | //
431 | CXDurationPickerDate newStartDate = [CXDurationPickerUtils pickerDateFromDate:n2];
432 |
433 | if ([self isPickerDateInPast:newStartDate] && !self.allowSelectionsInPast) {
434 | NSMutableDictionary *details = [NSMutableDictionary dictionary];
435 |
436 | [details setValue:@"Unable to set start date in the past." forKey:NSLocalizedDescriptionKey];
437 |
438 | *error = [NSError errorWithDomain:@"CXDurationPicker" code:100 userInfo:details];
439 |
440 | return NO;
441 | }
442 |
443 | [self clearCurrentDuration];
444 |
445 | _startDate.day = newStartDate.day;
446 | _startDate.month = newStartDate.month;
447 | _startDate.year = newStartDate.year;
448 |
449 | _endDate.day = pickerDate.day;
450 | _endDate.month = pickerDate.month;
451 | _endDate.year = pickerDate.year;
452 |
453 | [self createDuration];
454 |
455 | return YES;
456 | }
457 |
458 | - (BOOL)shiftDurationToStartPickerDate:(CXDurationPickerDate)pickerDate error:(NSError **)error {
459 | [self clearCurrentDuration];
460 |
461 | // Convert picker-dates to NSDates so we easily can do some calcs on them.
462 | //
463 | NSDate *d1 = [CXDurationPickerUtils dateFromPickerDate:self.startDate];
464 | NSDate *d2 = [CXDurationPickerUtils dateFromPickerDate:self.endDate];
465 | NSDate *n1 = [CXDurationPickerUtils dateFromPickerDate:pickerDate];
466 |
467 | // Calculate number of days in current duration, accounting for days in month.
468 | //
469 | NSDateComponents *diff = [self.calendar
470 | components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
471 | fromDate:d1 toDate:d2 options:0];
472 |
473 | // Calculate new ending date by adding difference.
474 | //
475 | NSDate *n2 = [self.calendar dateByAddingComponents:diff toDate:n1 options:0];
476 |
477 | // Convert back to our convenience model.
478 | //
479 | CXDurationPickerDate newEndDate = [CXDurationPickerUtils pickerDateFromDate:n2];
480 |
481 | _startDate.day = pickerDate.day;
482 | _startDate.month = pickerDate.month;
483 | _startDate.year = pickerDate.year;
484 |
485 | _endDate.day = newEndDate.day;
486 | _endDate.month = newEndDate.month;
487 | _endDate.year = newEndDate.year;
488 |
489 | [self createDuration];
490 |
491 | return YES;
492 | }
493 |
494 | #pragma mark - Internal
495 |
496 | - (void)addMonths {
497 | NSUInteger latestMonthIndex = [self.monthViews count];
498 |
499 | // This is to create 6 years month view
500 | for (int i = 0; i < 72; i++) {
501 | CXDurationPickerMonthView *view = [[CXDurationPickerMonthView alloc] initWithFrame:self.bounds];
502 |
503 | view.padding = UIEdgeInsetsMake(5, 0, 20, 0);
504 |
505 | view.monthIndex = latestMonthIndex + i;
506 |
507 | view.delegate = self;
508 |
509 | [view sizeToFit];
510 |
511 | [self.monthViews addObject:view];
512 | }
513 |
514 | [self.table reloadData];
515 | }
516 |
517 | - (void)addMonthsAsync {
518 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
519 | dispatch_async(dispatch_get_main_queue(), ^{
520 | [self addMonths];
521 | });
522 | });
523 | }
524 |
525 | - (void)changeSingleDateForDayView:(CXDurationPickerDayView *)dayView {
526 | CXDurationPickerDayView *oldDayView = [self dayForPickerDate:self.singleDate];
527 | oldDayView.type = CXDurationPickerDayTypeNormal;
528 |
529 | dayView.type = CXDurationPickerDayTypeSingle;
530 |
531 | _singleDate = dayView.pickerDate;
532 | }
533 |
534 | - (void)clearCurrentDuration {
535 | for (long i = 0, ii = [self.days count]; i < ii; i++) {
536 | CXDurationPickerDayView *day = (CXDurationPickerDayView *) [self.days objectAtIndex:i];
537 |
538 | day.type = CXDurationPickerDayTypeNormal;
539 | }
540 | }
541 |
542 | - (void)clearSingle {
543 | CXDurationPickerDayView *oldDayView = [self dayForPickerDate:self.singleDate];
544 |
545 | oldDayView.type = CXDurationPickerDayTypeNormal;
546 |
547 | oldDayView = nil;
548 | }
549 |
550 | - (void)createDuration {
551 | // Quick sanity test.
552 |
553 | if ([self hasEitherStartOrEndDate]) {
554 | if ([self hasStartDate]) {
555 | self.days = [self daysBetween:self.startDate and:self.startDate];
556 | } else {
557 | self.days = [self daysBetween:self.endDate and:self.endDate];
558 | }
559 | } else {
560 | self.days = [self daysBetween:self.startDate and:self.endDate];
561 | }
562 |
563 | [self clearCurrentDuration];
564 |
565 | CXDurationPickerDayView *day;
566 |
567 | if (self.days.count > 1) {
568 | day = (CXDurationPickerDayView *) [self.days firstObject];
569 |
570 | day.type = CXDurationPickerDayTypeStart;
571 | }
572 |
573 | day = (CXDurationPickerDayView *) [self.days lastObject];
574 |
575 | if (self.days.count == 1) {
576 | if ([self hasEitherStartOrEndDate]) {
577 | day.type = CXDurationPickerDayTypeSingle;
578 | } else {
579 | day.type = CXDurationPickerDayTypeOverlap;
580 | }
581 | } else {
582 | day.type = CXDurationPickerDayTypeEnd;
583 | }
584 |
585 | for (long i = 1, ii = [self.days count] - 1; i < ii; i++) {
586 | day = (CXDurationPickerDayView *) [self.days objectAtIndex:i];
587 |
588 | day.type = CXDurationPickerDayTypeTransit;
589 | }
590 | }
591 |
592 | - (BOOL)hasStartDate {
593 | return ! (self.startDate.year == 0);
594 | }
595 |
596 | - (BOOL)hasEndDate {
597 | return ! (self.endDate.year == 0);
598 | }
599 |
600 | - (BOOL)hasEitherStartOrEndDate {
601 | if ([self hasStartDate] && ! [self hasEndDate]) return YES;
602 | if ( ! [self hasStartDate] && [self hasEndDate]) return YES;
603 | return NO;
604 | }
605 |
606 | - (void)createSingle {
607 | CXDurationPickerDate today = [self pickerDateForToday];
608 |
609 | self.singleDate = today;
610 |
611 | CXDurationPickerDayView *dayView = [self dayForPickerDate:self.singleDate];
612 |
613 | dayView.type = CXDurationPickerDayTypeSingle;
614 | }
615 |
616 | - (CXDurationPickerDayView *)dayForPickerDate:(CXDurationPickerDate)pickerDate {
617 | if (pickerDate.year == 0) {
618 | return nil;
619 | }
620 |
621 | CXDurationPickerDayView *day;
622 |
623 | for (CXDurationPickerMonthView *monthView in self.monthViews) {
624 | if ([monthView containsDate:pickerDate]) {
625 | day = [monthView dayForPickerDate:pickerDate];
626 | break;
627 | }
628 | }
629 |
630 | return day;
631 | }
632 |
633 | - (NSMutableArray *)daysBetween:(CXDurationPickerDate)startDate and:(CXDurationPickerDate)endDate {
634 | BOOL searchingForStartMonth = YES;
635 |
636 | NSMutableArray *days = [[NSMutableArray alloc] init];
637 |
638 | for (CXDurationPickerMonthView *monthView in self.monthViews) {
639 | if (searchingForStartMonth) {
640 | if ([monthView containsDate:startDate]) {
641 | [days addObjectsFromArray:[self daysForMonthView:monthView forStartDate:startDate andEndDate:endDate]];
642 |
643 | searchingForStartMonth = NO;
644 |
645 | if ([monthView containsDate:endDate]) {
646 | break;
647 | }
648 |
649 | continue;
650 | }
651 |
652 | }
653 |
654 | [days addObjectsFromArray:[self daysForMonthView:monthView forStartDate:startDate andEndDate:endDate]];
655 |
656 | if ([monthView containsDate:endDate]) {
657 | break;
658 | }
659 | }
660 |
661 | return days;
662 | }
663 |
664 | - (NSArray *)daysForMonthView:(CXDurationPickerMonthView *)monthView
665 | forStartDate:(CXDurationPickerDate)startDate
666 | andEndDate:(CXDurationPickerDate)endDate {
667 |
668 | NSMutableArray *days = [NSMutableArray new];
669 |
670 | NSArray *dayViews = monthView.days;
671 |
672 | for (CXDurationPickerDayView *dayView in dayViews) {
673 | if ([dayView isBefore:startDate]) {
674 | continue;
675 | } else if ([dayView isAfter:endDate]) {
676 | break;
677 | } else {
678 | [days addObject:dayView];
679 | }
680 | }
681 |
682 | return days;
683 | }
684 |
685 |
686 | - (BOOL)isPickerDate:(CXDurationPickerDate)startPickerDate
687 | equalTo:(CXDurationPickerDate)endPickerDate {
688 |
689 | NSDate *startDate = [CXDurationPickerUtils dateFromPickerDate:startPickerDate];
690 | NSDate *endDate = [CXDurationPickerUtils dateFromPickerDate:endPickerDate];
691 |
692 | if (startDate == nil) {
693 | return NO;
694 | }
695 |
696 | if (endDate == nil) {
697 | return NO;
698 | }
699 |
700 | if ([startDate timeIntervalSinceDate:endDate] == 0) {
701 | return YES;
702 | }
703 |
704 | return NO;
705 | }
706 |
707 | - (BOOL)isPickerDateInPast:(CXDurationPickerDate)pickerDate {
708 | NSDate *today = [CXDurationPickerUtils today];
709 | NSDate *date = [CXDurationPickerUtils dateFromPickerDate:pickerDate];
710 |
711 | NSTimeInterval interval = [date timeIntervalSinceDate:today];
712 |
713 | if (interval < 0) {
714 | return YES;
715 | }
716 |
717 | return NO;
718 | }
719 |
720 | - (BOOL)isPickerDateYesterday:(CXDurationPickerDate)pickerDate {
721 | BOOL isYesterday = [CXDurationPickerUtils isPickerDateYesterday:pickerDate];
722 | return isYesterday;
723 | }
724 |
725 | - (BOOL)isDurationValidForStartPickerDate:(CXDurationPickerDate)startPickerDate
726 | andEndPickerDate:(CXDurationPickerDate)endPickerDate {
727 |
728 | NSDate *startDate = [CXDurationPickerUtils dateFromPickerDate:startPickerDate];
729 | NSDate *endDate = [CXDurationPickerUtils dateFromPickerDate:endPickerDate];
730 |
731 | if (endPickerDate.year == 0) return true;
732 |
733 | if ([startDate timeIntervalSinceDate:endDate] > 0) {
734 | return NO;
735 | }
736 |
737 | if ([endDate timeIntervalSinceDate:startDate] < 0) {
738 | return NO;
739 | }
740 |
741 | return YES;
742 | }
743 |
744 | - (NSIndexPath *)indexPathForPickerDate:(CXDurationPickerDate)pickerDate {
745 | CXDurationPickerMonthView *monthView = [self monthForPickerDate:pickerDate];
746 |
747 | if (monthView) {
748 | return [NSIndexPath indexPathForRow:monthView.monthIndex inSection:0];
749 | } else {
750 | return nil;
751 | }
752 | }
753 |
754 | - (CXDurationPickerMonthView *)monthForPickerDate:(CXDurationPickerDate)pickerDate {
755 | if (pickerDate.year == 0) {
756 | return nil;
757 | }
758 |
759 | CXDurationPickerMonthView *month;
760 |
761 | for (CXDurationPickerMonthView *monthView in self.monthViews) {
762 | if ([monthView containsDate:pickerDate]) {
763 | month = monthView;
764 | break;
765 | }
766 | }
767 |
768 | return month;
769 | }
770 |
771 | - (CXDurationPickerMonthView *)monthViewForRow:(NSInteger)row {
772 | CXDurationPickerMonthView *view;
773 |
774 | if (row >= [self.monthViews count]) {
775 | view = [[CXDurationPickerMonthView alloc] initWithFrame:self.bounds];
776 |
777 | view.monthIndex = row;
778 |
779 | [view sizeToFit];
780 | } else {
781 | view = [self.monthViews objectAtIndex:row];
782 | }
783 |
784 | return view;
785 | }
786 |
787 | - (CXDurationPickerDate)pickerDateBetweenStartDate:(NSDate*)startDate andEndDate:(NSDate*)endDate {
788 | NSDate *d1;
789 | NSDate *d2;
790 |
791 | [self.calendar rangeOfUnit:NSCalendarUnitDay startDate:&d1
792 | interval:nil forDate:startDate];
793 |
794 | [self.calendar rangeOfUnit:NSCalendarUnitDay startDate:&d2
795 | interval:nil forDate:endDate];
796 |
797 | NSDateComponents *components = [self.calendar
798 | components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
799 | fromDate:d1 toDate:d2 options:0];
800 |
801 |
802 | return (CXDurationPickerDate) {
803 | components.year,
804 | components.month,
805 | components.day
806 | };
807 | }
808 |
809 | - (CXDurationPickerDate)pickerDateForToday {
810 | NSDate *todayDate = [NSDate date];
811 |
812 | NSDateComponents *todayComponents = [[NSCalendar currentCalendar]
813 | components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
814 | fromDate:todayDate];
815 |
816 | CXDurationPickerDate todayPickerDate;
817 |
818 | todayPickerDate.day = todayComponents.day;
819 | todayPickerDate.month = todayComponents.month;
820 | todayPickerDate.year = todayComponents.year;
821 |
822 | return todayPickerDate;
823 | }
824 |
825 |
826 | - (CXDurationPickerDate)pickerDateForTomorrow {
827 | NSCalendar *calendar = [NSCalendar currentCalendar];
828 | NSDate *todayDate = [NSDate date];
829 |
830 | NSDateComponents *components = [NSDateComponents new];
831 | components.day = 2;
832 | //components.month = 1;
833 |
834 | NSDate *tomorrowDate = [calendar dateByAddingComponents:components toDate:todayDate options:0];
835 |
836 | CXDurationPickerDate pickerDate = [CXDurationPickerUtils pickerDateFromDate:tomorrowDate];
837 |
838 | return pickerDate;
839 | }
840 |
841 | #pragma mark - Colors
842 |
843 | - (void)setDayLabelColor:(UIColor *)color {
844 | _dayLabelColor = color;
845 | [self.table reloadData];
846 | }
847 |
848 | - (void)setMonthLabelColor:(UIColor *)color {
849 | _monthLabelColor = color;
850 | [self.table reloadData];
851 | }
852 |
853 | - (void)setBackgroundColor:(UIColor *)color {
854 | [self.table setBackgroundColor:color];
855 | [self.table reloadData];
856 | }
857 |
858 | - (void)setDisabledDayBackgroundColor:(UIColor *)color {
859 | _disabledDayBackgroundColor = color;
860 | [self.table reloadData];
861 | }
862 |
863 | - (void)setDisabledDayForegroundColor:(UIColor *)color {
864 | _disabledDayForegroundColor = color;
865 | [self.table reloadData];
866 | }
867 |
868 | - (void)setGridColor:(UIColor *)color {
869 | _gridColor = color;
870 | [self.table reloadData];
871 | }
872 |
873 | - (void)setTerminalBackgroundColor:(UIColor *)color {
874 | _terminalBackgroundColor = color;
875 | [self.table reloadData];
876 | }
877 |
878 | - (void)setTerminalForegroundColor:(UIColor *)color {
879 | _terminalForegroundColor = color;
880 | [self.table reloadData];
881 | }
882 |
883 | - (void)setTodayBackgroundColor:(UIColor *)color {
884 | _todayBackgroundColor = color;
885 | [self.table reloadData];
886 | }
887 |
888 | - (void)setTodayForegroundColor:(UIColor *)color {
889 | _todayForegroundColor = color;
890 | [self.table reloadData];
891 | }
892 |
893 | - (void)setTransitBackgroundColor:(UIColor *)color {
894 | _transitBackgroundColor = color;
895 | [self.table reloadData];
896 | }
897 |
898 | - (void)setTransitForegroundColor:(UIColor *)color {
899 | _transitForegroundColor = color;
900 | [self.table reloadData];
901 | }
902 |
903 | @end
904 |
--------------------------------------------------------------------------------