├── 自定义时间控件 ├── JGDate.gif ├── JGDateTime │ ├── JGDateTime │ │ ├── Assets.xcassets │ │ │ ├── Contents.json │ │ │ ├── selected.imageset │ │ │ │ ├── selected.png │ │ │ │ ├── selected@2x.png │ │ │ │ ├── selected@3x.png │ │ │ │ └── Contents.json │ │ │ ├── pickerDelete.imageset │ │ │ │ ├── pickerDelete.png │ │ │ │ ├── pickerDelete@2x.png │ │ │ │ ├── pickerDelete@3x.png │ │ │ │ └── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Controllers │ │ │ ├── MainViewController.h │ │ │ ├── JGRootViewController.h │ │ │ ├── MainViewController.m │ │ │ ├── MainViewController.xib │ │ │ └── JGRootViewController.m │ │ ├── TimeTools │ │ │ ├── Style3 │ │ │ │ └── GFCalendar │ │ │ │ │ ├── GFCalendar.h │ │ │ │ │ ├── GFCalendarCell.h │ │ │ │ │ ├── GFCalendarScrollView.h │ │ │ │ │ ├── GFCalendarMonth.h │ │ │ │ │ ├── GFCalendarView.h │ │ │ │ │ ├── NSDate+GFCalendar.h │ │ │ │ │ ├── GFCalendarMonth.m │ │ │ │ │ ├── GFCalendarCell.m │ │ │ │ │ ├── NSDate+GFCalendar.m │ │ │ │ │ └── GFCalendarView.m │ │ │ ├── Style2 │ │ │ │ ├── Masonry │ │ │ │ │ ├── MASLayoutConstraint.m │ │ │ │ │ ├── NSLayoutConstraint+MASDebugAdditions.h │ │ │ │ │ ├── MASLayoutConstraint.h │ │ │ │ │ ├── MASCompositeConstraint.h │ │ │ │ │ ├── Masonry.h │ │ │ │ │ ├── ViewController+MASAdditions.h │ │ │ │ │ ├── NSArray+MASShorthandAdditions.h │ │ │ │ │ ├── MASViewAttribute.m │ │ │ │ │ ├── MASViewAttribute.h │ │ │ │ │ ├── ViewController+MASAdditions.m │ │ │ │ │ ├── MASViewConstraint.h │ │ │ │ │ ├── MASConstraint+Private.h │ │ │ │ │ ├── NSArray+MASAdditions.h │ │ │ │ │ ├── View+MASShorthandAdditions.h │ │ │ │ │ ├── View+MASAdditions.h │ │ │ │ │ ├── MASCompositeConstraint.m │ │ │ │ │ ├── MASConstraintMaker.h │ │ │ │ │ ├── View+MASAdditions.m │ │ │ │ │ ├── NSLayoutConstraint+MASDebugAdditions.m │ │ │ │ │ ├── MASUtilities.h │ │ │ │ │ ├── NSArray+MASAdditions.m │ │ │ │ │ ├── MASConstraint.h │ │ │ │ │ ├── MASConstraint.m │ │ │ │ │ └── MASConstraintMaker.m │ │ │ │ └── JGPicker │ │ │ │ │ ├── JGPicker.h │ │ │ │ │ └── JGPicker.m │ │ │ ├── Style1 │ │ │ │ ├── CycleScollview │ │ │ │ │ ├── RBCustomDatePickerView.h │ │ │ │ │ ├── MXSCycleScrollView.h │ │ │ │ │ └── MXSCycleScrollView.m │ │ │ │ └── FDAlertView │ │ │ │ │ └── FDAlertView.h │ │ │ ├── Style4 │ │ │ │ └── JGPicker │ │ │ │ │ └── JGPickerView.h │ │ │ └── Style5 │ │ │ │ ├── NYDateTableViewCell.h │ │ │ │ ├── NYDateTimeTableViewCell.h │ │ │ │ ├── NYDateTableViewCell.m │ │ │ │ ├── NYDateTimeTableViewCell.xib │ │ │ │ └── NYDateTableViewCell.xib │ │ ├── APPS │ │ │ ├── JGAppDelegate.h │ │ │ └── JGAppDelegate.m │ │ ├── main.m │ │ ├── Info.plist │ │ └── Base.lproj │ │ │ ├── Main.storyboard │ │ │ └── LaunchScreen.storyboard │ ├── JGDateTime.xcodeproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ ├── JGDateTimeTests │ │ ├── Info.plist │ │ └── JGDateTimeTests.m │ └── JGDateTimeUITests │ │ ├── Info.plist │ │ └── JGDateTimeUITests.m └── JGDateTimeDemo │ ├── JGDateTimeDemo.xcodeproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── JGDateTimeDemo │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── CycleScollview │ │ ├── RBCustomDatePickerView.h │ │ ├── MXSCycleScrollView.h │ │ └── MXSCycleScrollView.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.m │ ├── FDAlertView │ │ └── FDAlertView.h │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ └── AppDelegate.m │ ├── JGDateTimeDemoTests │ ├── Info.plist │ └── JGDateTimeDemoTests.m │ └── JGDateTimeDemoUITests │ ├── Info.plist │ └── JGDateTimeDemoUITests.m ├── README.md └── .gitignore /自定义时间控件/JGDate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDate.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JGDateTime 2 | ##日期选择汇总 3 | ###效果图 4 | ![Mou icon](https://github.com/mengzhihun6/JGDateTime/blob/master/自定义时间控件/JGDate.gif) 5 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/selected.png -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/selected@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/selected@2x.png -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/selected@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/selected@3x.png -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/pickerDelete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/pickerDelete.png -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/pickerDelete@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/pickerDelete@2x.png -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/pickerDelete@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengzhihun6/JGDateTime/HEAD/自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/pickerDelete@3x.png -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Controllers/MainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.h 3 | // NYDateTimePicker 4 | // 5 | // Created by 牛严 on 15/9/22. 6 | // Copyright (c) 2015年 牛严. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MainViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JGDateTimeDemo 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendar.h: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendar.h 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #ifndef GFCalendar_h 9 | #define GFCalendar_h 10 | 11 | #import "GFCalendarView.h" 12 | 13 | #endif /* GFCalendar_h */ 14 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Controllers/JGRootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGRootViewController.h 3 | // JGDateTime 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JGRootViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASLayoutConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASLayoutConstraint.h" 10 | 11 | @implementation MASLayoutConstraint 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/APPS/JGAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGAppDelegate.h 3 | // JGDateTime 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JGAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JGDateTimeDemo 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JGDateTime 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JGAppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([JGAppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JGDateTimeDemo 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. 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 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarCell.h 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface GFCalendarCell : UICollectionViewCell 11 | 12 | @property (nonatomic, strong) UIView *todayCircle; //!< 标示'今天' 13 | @property (nonatomic, strong) UILabel *todayLabel; //!< 标示日期(几号) 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/NSLayoutConstraint+MASDebugAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * makes debug and log output of NSLayoutConstraints more readable 13 | */ 14 | @interface NSLayoutConstraint (MASDebugAdditions) 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/selected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selected.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "selected@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "selected@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/pickerDelete.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "pickerDelete.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "pickerDelete@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "pickerDelete@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarScrollView.h 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | typedef void (^DidSelectDayHandler)(NSInteger, NSInteger, NSInteger); 11 | 12 | @interface GFCalendarScrollView : UIScrollView 13 | 14 | 15 | @property (nonatomic, copy) DidSelectDayHandler didSelectDayHandler; // 日期点击回调 16 | 17 | - (void)refreshToCurrentMonth; // 刷新 calendar 回到当前日期月份 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/CycleScollview/RBCustomDatePickerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBCustomDatePickerView.h 3 | // RBCustomDateTimePicker 4 | // e-mail:rbyyy924805@163.com 5 | // Created by renbing on 3/17/14. 6 | // Copyright (c) 2014 renbing. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MXSCycleScrollView.h" 11 | 12 | 13 | @protocol sendTheValueDelegate 14 | 15 | -(void)getTimeToValue:(NSString *)theTimeStr; 16 | 17 | 18 | @end 19 | 20 | @interface RBCustomDatePickerView : UIView 21 | @property(nonatomic,assign)id delegate; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style1/CycleScollview/RBCustomDatePickerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBCustomDatePickerView.h 3 | // RBCustomDateTimePicker 4 | // e-mail:rbyyy924805@163.com 5 | // Created by renbing on 3/17/14. 6 | // Copyright (c) 2014 renbing. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MXSCycleScrollView.h" 11 | 12 | 13 | @protocol sendTheValueDelegate 14 | 15 | -(void)getTimeToValue:(NSString *)theTimeStr; 16 | 17 | 18 | @end 19 | 20 | @interface RBCustomDatePickerView : UIView 21 | @property(nonatomic,assign)id delegate; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASLayoutConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * When you are debugging or printing the constraints attached to a view this subclass 13 | * makes it easier to identify which constraints have been created via Masonry 14 | */ 15 | @interface MASLayoutConstraint : NSLayoutConstraint 16 | 17 | /** 18 | * a key to associate with this constraint 19 | */ 20 | @property (nonatomic, strong) id mas_key; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASCompositeConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | /** 13 | * A group of MASConstraint objects 14 | */ 15 | @interface MASCompositeConstraint : MASConstraint 16 | 17 | /** 18 | * Creates a composite with a predefined array of children 19 | * 20 | * @param children child MASConstraints 21 | * 22 | * @return a composite constraint 23 | */ 24 | - (id)initWithChildren:(NSArray *)children; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarMonth.h: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarMonth.h 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | // 月份模型类 8 | // 9 | 10 | #import 11 | 12 | @interface GFCalendarMonth : NSObject 13 | 14 | @property (nonatomic, strong) NSDate *monthDate; //!< 传入的 NSDate 对象,该 NSDate 对象代表当前月的某一日,根据它来获得其他数据 15 | @property (nonatomic, assign) NSInteger totalDays; //!< 当前月的天数 16 | @property (nonatomic, assign) NSInteger firstWeekday; //!< 标示第一天是星期几(0代表周日,1代表周一,以此类推) 17 | @property (nonatomic, assign) NSInteger year; //!< 所属年份 18 | @property (nonatomic, assign) NSInteger month; //!< 当前月份 19 | 20 | - (instancetype)initWithDate:(NSDate *)date; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTimeTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTimeUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemoUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style4/JGPicker/JGPickerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGPickerView.h 3 | // JG5ColDataPicker 4 | // 5 | // Created by stkcctv on 16/12/19. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol JGPickerViewDelegate 12 | 13 | @optional 14 | -(void)didFinishPickView:(NSString*)date; 15 | -(void)pickerviewbuttonclick:(UIButton *)sender; 16 | //-(void)hiddenPickerView; 17 | 18 | 19 | @end 20 | 21 | @interface JGPickerView : UIView 22 | 23 | @property (nonatomic, copy) NSString *province; 24 | @property(nonatomic,strong)NSDate*curDate; 25 | //@property (nonatomic,strong)UITextField *myTextField; 26 | @property (nonatomic,strong)UIButton *myButton; 27 | 28 | @property(nonatomic,strong)iddelegate; 29 | - (void)showInView:(UIView *)view; 30 | - (void)hiddenPickerView; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarView.h: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarView.h 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | typedef void (^DidSelectDayHandler)(NSInteger, NSInteger, NSInteger); 11 | 12 | @interface GFCalendarView : UIView 13 | 14 | 15 | /** 16 | * 构造方法 17 | * 18 | * @param origin calendar 的位置 19 | * @param width calendar 的宽度(高度会根据给定的宽度自动计算) 20 | * 21 | * @return bannerView对象 22 | */ 23 | - (instancetype)initWithFrameOrigin:(CGPoint)origin width:(CGFloat)width; 24 | 25 | 26 | /** 27 | * calendar 的高度(只读属性) 28 | */ 29 | @property (nonatomic, assign, readonly) CGFloat calendarHeight; 30 | 31 | 32 | /** 33 | * 日期点击回调 34 | * block 的参数表示当前日期的 NSDate 对象 35 | */ 36 | @property (nonatomic, copy) DidSelectDayHandler didSelectDayHandler; 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/NSDate+GFCalendar.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+GFCalendar.h 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface NSDate (GFCalendar) 11 | 12 | /** 13 | * 获得当前 NSDate 对象对应的日子 14 | */ 15 | - (NSInteger)dateDay; 16 | 17 | /** 18 | * 获得当前 NSDate 对象对应的月份 19 | */ 20 | - (NSInteger)dateMonth; 21 | 22 | /** 23 | * 获得当前 NSDate 对象对应的年份 24 | */ 25 | - (NSInteger)dateYear; 26 | 27 | /** 28 | * 获得当前 NSDate 对象的上个月的某一天(此处定为15号)的 NSDate 对象 29 | */ 30 | - (NSDate *)previousMonthDate; 31 | 32 | /** 33 | * 获得当前 NSDate 对象的下个月的某一天(此处定为15号)的 NSDate 对象 34 | */ 35 | - (NSDate *)nextMonthDate; 36 | 37 | /** 38 | * 获得当前 NSDate 对象对应的月份的总天数 39 | */ 40 | - (NSInteger)totalDaysInMonth; 41 | 42 | /** 43 | * 获得当前 NSDate 对象对应月份当月第一天的所属星期 44 | */ 45 | - (NSInteger)firstWeekDayInMonth; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/Masonry.h: -------------------------------------------------------------------------------- 1 | // 2 | // Masonry.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Masonry. 12 | FOUNDATION_EXPORT double MasonryVersionNumber; 13 | 14 | //! Project version string for Masonry. 15 | FOUNDATION_EXPORT const unsigned char MasonryVersionString[]; 16 | 17 | #import "MASUtilities.h" 18 | #import "View+MASAdditions.h" 19 | #import "View+MASShorthandAdditions.h" 20 | #import "ViewController+MASAdditions.h" 21 | #import "NSArray+MASAdditions.h" 22 | #import "NSArray+MASShorthandAdditions.h" 23 | #import "MASConstraint.h" 24 | #import "MASCompositeConstraint.h" 25 | #import "MASViewAttribute.h" 26 | #import "MASViewConstraint.h" 27 | #import "MASConstraintMaker.h" 28 | #import "MASLayoutConstraint.h" 29 | #import "NSLayoutConstraint+MASDebugAdditions.h" 30 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/ViewController+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Craig Siemens on 2015-06-23. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | #ifdef MAS_VIEW_CONTROLLER 14 | 15 | @interface MAS_VIEW_CONTROLLER (MASAdditions) 16 | 17 | /** 18 | * following properties return a new MASViewAttribute with appropriate UILayoutGuide and NSLayoutAttribute 19 | */ 20 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom; 26 | 27 | 28 | @end 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style5/NYDateTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // NYDateTableViewCell.h 3 | // NYDateTimePicker 4 | // 5 | // Created by 牛严 on 15/9/24. 6 | // Copyright (c) 2015年 牛严. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol NYDatePickerDelegate; 12 | 13 | @interface NYDateTableViewCell : UITableViewCell 14 | @property (strong, nonatomic) IBOutlet UILabel *dateLabel; 15 | @property (strong, nonatomic) IBOutlet UIDatePicker *datePicker; 16 | @property (strong, nonatomic) IBOutlet UIView *grayView; 17 | @property (assign) NSInteger ShowAndDisapper; 18 | @property BOOL ifChosen; 19 | 20 | @property (assign, nonatomic) id delegate; 21 | 22 | -(void)reloadWithDate:(NSString *)dateString; 23 | -(void)pickerViewSetDate:(NSDate *)date; 24 | -(void)grayViewAnimation; 25 | -(void)fadePickerViewAnimation; 26 | -(void)showPickerViewAnimation; 27 | 28 | @end 29 | 30 | @protocol NYDatePickerDelegate 31 | 32 | 33 | -(void)oneDateCellHeightChange:(BOOL)ifChosen; 34 | -(void)oneDatePickerValueChanged:(NSString *)dateString; 35 | 36 | @end -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTimeTests/JGDateTimeTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGDateTimeTests.m 3 | // JGDateTimeTests 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JGDateTimeTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JGDateTimeTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarMonth.m: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarMonth.m 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import "GFCalendarMonth.h" 9 | #import "NSDate+GFCalendar.h" 10 | 11 | @implementation GFCalendarMonth 12 | 13 | - (instancetype)initWithDate:(NSDate *)date { 14 | 15 | if (self = [super init]) { 16 | 17 | _monthDate = date; 18 | 19 | _totalDays = [self setupTotalDays]; 20 | _firstWeekday = [self setupFirstWeekday]; 21 | _year = [self setupYear]; 22 | _month = [self setupMonth]; 23 | 24 | } 25 | 26 | return self; 27 | 28 | } 29 | 30 | 31 | - (NSInteger)setupTotalDays { 32 | return [_monthDate totalDaysInMonth]; 33 | } 34 | 35 | - (NSInteger)setupFirstWeekday { 36 | return [_monthDate firstWeekDayInMonth]; 37 | } 38 | 39 | - (NSInteger)setupYear { 40 | return [_monthDate dateYear]; 41 | } 42 | 43 | - (NSInteger)setupMonth { 44 | return [_monthDate dateMonth]; 45 | } 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style5/NYDateTimeTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // NYDateTimeTableViewCell.h 3 | // NYDateTimePicker 4 | // 5 | // Created by 牛严 on 15/9/23. 6 | // Copyright (c) 2015年 牛严. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol NYDateTimeDelegate; 12 | 13 | @interface NYDateTimeTableViewCell : UITableViewCell 14 | @property (strong, nonatomic) IBOutlet UIView *grayView; 15 | @property (strong, nonatomic) IBOutlet UILabel *dateTimeLabel; 16 | @property (strong, nonatomic) IBOutlet UIPickerView *datePickerView; 17 | @property BOOL ifChosen; 18 | @property (assign, nonatomic) id delegate; 19 | 20 | -(void)reloadWithDate:(NSString *)dateString; 21 | -(void)pickerViewSetDate:(NSDate *)date; 22 | -(void)grayViewAnimation; 23 | -(void)showPickerViewAnimation; 24 | -(void)fadePickerViewAnimation; 25 | 26 | @end 27 | 28 | @protocol NYDateTimeDelegate 29 | //更改高度 30 | -(void)oneTimeCellHeightChange:(BOOL)ifChosen; 31 | //更改内容 32 | -(void)oneTimePickerValueChanged:(NSString *)dateString; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemoTests/JGDateTimeDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGDateTimeDemoTests.m 3 | // JGDateTimeDemoTests 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JGDateTimeDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JGDateTimeDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/NSArray+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand array additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface NSArray (MASShorthandAdditions) 18 | 19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 22 | 23 | @end 24 | 25 | @implementation NSArray (MASShorthandAdditions) 26 | 27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 28 | return [self mas_makeConstraints:block]; 29 | } 30 | 31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 32 | return [self mas_updateConstraints:block]; 33 | } 34 | 35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 36 | return [self mas_remakeConstraints:block]; 37 | } 38 | 39 | @end 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/JGPicker/JGPicker.h: -------------------------------------------------------------------------------- 1 | // 2 | // JGPicker.h 3 | // JGPicker 4 | // 5 | // Created by stkcctv on 16/12/14. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol JGPickerDelegate 12 | 13 | //改变了 14 | - (void)changeTime:(NSDate *)date; 15 | //确定选择 16 | - (void)determinSelected:(NSDate *)date; 17 | 18 | @end 19 | 20 | @interface JGPicker : UIView 21 | 22 | @property (nonatomic,assign)id delegate; 23 | 24 | 25 | @property (nonatomic,assign)UIDatePickerMode type; 26 | 27 | @property (nonatomic,strong)UIView *backgroundView; 28 | @property (nonatomic,strong)UIView *topView; 29 | @property (nonatomic,strong)UIDatePicker *datePicker; 30 | 31 | @property (nonatomic,strong)UIButton *cancleButton; 32 | 33 | @property (nonatomic,strong)UIButton *determineButton; 34 | 35 | 36 | //类方法创建 37 | +(instancetype)datePickerViewWithType:(UIDatePickerMode)type andDelegate:(id)delegate;; 38 | //实例方法创建 39 | - (instancetype)initWithFrame:(CGRect)frame type:(UIDatePickerMode)type andDelegate:(id)delegate; 40 | 41 | - (void)show; 42 | 43 | // NSDate <-- NSString 44 | - (NSDate*)dateFromString:(NSString*)dateString; 45 | // NSDate --> NSString 46 | - (NSString*)stringFromDate:(NSDate*)date; 47 | 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarCell.m 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import "GFCalendarCell.h" 9 | 10 | @implementation GFCalendarCell 11 | 12 | - (instancetype)initWithFrame:(CGRect)frame { 13 | 14 | if (self = [super initWithFrame:frame]) { 15 | 16 | [self addSubview:self.todayCircle]; 17 | [self addSubview:self.todayLabel]; 18 | 19 | } 20 | 21 | return self; 22 | } 23 | 24 | - (UIView *)todayCircle { 25 | if (_todayCircle == nil) { 26 | _todayCircle = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.8 * self.bounds.size.height, 0.8 * self.bounds.size.height)]; 27 | _todayCircle.center = CGPointMake(0.5 * self.bounds.size.width, 0.5 * self.bounds.size.height); 28 | _todayCircle.layer.cornerRadius = 0.5 * _todayCircle.frame.size.width; 29 | } 30 | return _todayCircle; 31 | } 32 | 33 | - (UILabel *)todayLabel { 34 | if (_todayLabel == nil) { 35 | _todayLabel = [[UILabel alloc] initWithFrame:self.bounds]; 36 | _todayLabel.textAlignment = NSTextAlignmentCenter; 37 | _todayLabel.font = [UIFont boldSystemFontOfSize:15.0]; 38 | _todayLabel.backgroundColor = [UIColor clearColor]; 39 | } 40 | return _todayLabel; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTimeUITests/JGDateTimeUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGDateTimeUITests.m 3 | // JGDateTimeUITests 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JGDateTimeUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JGDateTimeUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemoUITests/JGDateTimeDemoUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGDateTimeDemoUITests.m 3 | // JGDateTimeDemoUITests 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JGDateTimeDemoUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JGDateTimeDemoUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASViewAttribute.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | 11 | @implementation MASViewAttribute 12 | 13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute { 14 | self = [self initWithView:view item:view layoutAttribute:layoutAttribute]; 15 | return self; 16 | } 17 | 18 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute { 19 | self = [super init]; 20 | if (!self) return nil; 21 | 22 | _view = view; 23 | _item = item; 24 | _layoutAttribute = layoutAttribute; 25 | 26 | return self; 27 | } 28 | 29 | - (BOOL)isSizeAttribute { 30 | return self.layoutAttribute == NSLayoutAttributeWidth 31 | || self.layoutAttribute == NSLayoutAttributeHeight; 32 | } 33 | 34 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute { 35 | if ([viewAttribute isKindOfClass:self.class]) { 36 | return self.view == viewAttribute.view 37 | && self.layoutAttribute == viewAttribute.layoutAttribute; 38 | } 39 | return [super isEqual:viewAttribute]; 40 | } 41 | 42 | - (NSUInteger)hash { 43 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JGDateTimeDemo 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "FDAlertView.h" 11 | #import "RBCustomDatePickerView.h" 12 | 13 | 14 | @interface ViewController () 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | // Do any additional setup after loading the view, typically from a nib. 23 | UIButton * btn=[UIButton buttonWithType:UIButtonTypeContactAdd]; 24 | btn.frame=CGRectMake(100, 100, 100, 100); 25 | [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; 26 | 27 | [self.view addSubview:btn]; 28 | 29 | } 30 | 31 | -(void)btnClick 32 | { 33 | FDAlertView *alert = [[FDAlertView alloc] init]; 34 | RBCustomDatePickerView * contentView=[[RBCustomDatePickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)]; 35 | contentView.delegate=self; 36 | alert.contentView = contentView; 37 | [alert show]; 38 | 39 | } 40 | 41 | 42 | -(void)getTimeToValue:(NSString *)theTimeStr 43 | { 44 | NSLog(@"我获取到时间了,时间是===%@",theTimeStr); 45 | } 46 | 47 | 48 | 49 | - (void)didReceiveMemoryWarning { 50 | [super didReceiveMemoryWarning]; 51 | // Dispose of any resources that can be recreated. 52 | } 53 | 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASViewAttribute.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * An immutable tuple which stores the view and the related NSLayoutAttribute. 13 | * Describes part of either the left or right hand side of a constraint equation 14 | */ 15 | @interface MASViewAttribute : NSObject 16 | 17 | /** 18 | * The view which the reciever relates to. Can be nil if item is not a view. 19 | */ 20 | @property (nonatomic, weak, readonly) MAS_VIEW *view; 21 | 22 | /** 23 | * The item which the reciever relates to. 24 | */ 25 | @property (nonatomic, weak, readonly) id item; 26 | 27 | /** 28 | * The attribute which the reciever relates to 29 | */ 30 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute; 31 | 32 | /** 33 | * Convenience initializer. 34 | */ 35 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute; 36 | 37 | /** 38 | * The designated initializer. 39 | */ 40 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute; 41 | 42 | /** 43 | * Determine whether the layoutAttribute is a size attribute 44 | * 45 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight 46 | */ 47 | - (BOOL)isSizeAttribute; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/ViewController+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Craig Siemens on 2015-06-23. 6 | // 7 | // 8 | 9 | #import "ViewController+MASAdditions.h" 10 | 11 | #ifdef MAS_VIEW_CONTROLLER 12 | 13 | @implementation MAS_VIEW_CONTROLLER (MASAdditions) 14 | 15 | - (MASViewAttribute *)mas_topLayoutGuide { 16 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 17 | } 18 | - (MASViewAttribute *)mas_topLayoutGuideTop { 19 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 20 | } 21 | - (MASViewAttribute *)mas_topLayoutGuideBottom { 22 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 23 | } 24 | 25 | - (MASViewAttribute *)mas_bottomLayoutGuide { 26 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 27 | } 28 | - (MASViewAttribute *)mas_bottomLayoutGuideTop { 29 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 30 | } 31 | - (MASViewAttribute *)mas_bottomLayoutGuideBottom { 32 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 33 | } 34 | 35 | 36 | 37 | @end 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASViewConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | #import "MASUtilities.h" 13 | 14 | /** 15 | * A single constraint. 16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view 17 | */ 18 | @interface MASViewConstraint : MASConstraint 19 | 20 | /** 21 | * First item/view and first attribute of the NSLayoutConstraint 22 | */ 23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute; 24 | 25 | /** 26 | * Second item/view and second attribute of the NSLayoutConstraint 27 | */ 28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute; 29 | 30 | /** 31 | * initialises the MASViewConstraint with the first part of the equation 32 | * 33 | * @param firstViewAttribute view.mas_left, view.mas_width etc. 34 | * 35 | * @return a new view constraint 36 | */ 37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute; 38 | 39 | /** 40 | * Returns all MASViewConstraints installed with this view as a first item. 41 | * 42 | * @param view A view to retrieve constraints for. 43 | * 44 | * @return An array of MASViewConstraints. 45 | */ 46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/CycleScollview/MXSCycleScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MXSCycleScrollView.h 3 | // xuexin 4 | // e-mail:rbyyy924805@163.com 5 | // Created by renbing on 3/7/14. 6 | // Copyright (c) 2014 renbing. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol MXSCycleScrollViewDelegate; 12 | @protocol MXSCycleScrollViewDatasource; 13 | 14 | @interface MXSCycleScrollView : UIView 15 | { 16 | UIScrollView *_scrollView; 17 | 18 | NSInteger _totalPages; 19 | NSInteger _curPage; 20 | 21 | NSMutableArray *_curViews; 22 | } 23 | 24 | @property (nonatomic,readonly) UIScrollView *scrollView; 25 | @property (nonatomic,assign) NSInteger currentPage; 26 | @property (nonatomic,assign,setter = setDataource:) id datasource; 27 | @property (nonatomic,assign,setter = setDelegate:) id delegate; 28 | 29 | - (void)setCurrentSelectPage:(NSInteger)selectPage; //设置初始化页数 30 | - (void)reloadData; 31 | - (void)setViewContent:(UIView *)view atIndex:(NSInteger)index; 32 | 33 | @end 34 | 35 | @protocol MXSCycleScrollViewDelegate 36 | 37 | @optional 38 | - (void)didClickPage:(MXSCycleScrollView *)csView atIndex:(NSInteger)index; 39 | - (void)scrollviewDidChangeNumber; 40 | 41 | @end 42 | 43 | @protocol MXSCycleScrollViewDatasource 44 | 45 | @required 46 | - (NSInteger)numberOfPages:(MXSCycleScrollView*)scrollView; 47 | - (UIView *)pageAtIndex:(NSInteger)index andScrollView:(MXSCycleScrollView*)scrollView; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style1/CycleScollview/MXSCycleScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MXSCycleScrollView.h 3 | // xuexin 4 | // e-mail:rbyyy924805@163.com 5 | // Created by renbing on 3/7/14. 6 | // Copyright (c) 2014 renbing. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol MXSCycleScrollViewDelegate; 12 | @protocol MXSCycleScrollViewDatasource; 13 | 14 | @interface MXSCycleScrollView : UIView 15 | { 16 | UIScrollView *_scrollView; 17 | 18 | NSInteger _totalPages; 19 | NSInteger _curPage; 20 | 21 | NSMutableArray *_curViews; 22 | } 23 | 24 | @property (nonatomic,readonly) UIScrollView *scrollView; 25 | @property (nonatomic,assign) NSInteger currentPage; 26 | @property (nonatomic,assign,setter = setDataource:) id datasource; 27 | @property (nonatomic,assign,setter = setDelegate:) id delegate; 28 | 29 | - (void)setCurrentSelectPage:(NSInteger)selectPage; //设置初始化页数 30 | - (void)reloadData; 31 | - (void)setViewContent:(UIView *)view atIndex:(NSInteger)index; 32 | 33 | @end 34 | 35 | @protocol MXSCycleScrollViewDelegate 36 | 37 | @optional 38 | - (void)didClickPage:(MXSCycleScrollView *)csView atIndex:(NSInteger)index; 39 | - (void)scrollviewDidChangeNumber; 40 | 41 | @end 42 | 43 | @protocol MXSCycleScrollViewDatasource 44 | 45 | @required 46 | - (NSInteger)numberOfPages:(MXSCycleScrollView*)scrollView; 47 | - (UIView *)pageAtIndex:(NSInteger)index andScrollView:(MXSCycleScrollView*)scrollView; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/FDAlertView/FDAlertView.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDAlertView.h 3 | // FDAlertViewDemo 4 | // 5 | // Created by fergusding on 15/5/26. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol FDAlertViewDelegate; 12 | 13 | @interface FDAlertView : UIView 14 | 15 | @property (strong, nonatomic) UIView *contentView; 16 | @property (strong, nonatomic) UIImage *icon; 17 | @property (strong, nonatomic) NSString *title; 18 | @property (strong, nonatomic) NSString *message; 19 | @property (weak, nonatomic) id delegate; 20 | 21 | - (instancetype)initWithTitle:(NSString *)title icon:(UIImage *)icon message:(NSString *)message delegate:(id)delegate buttonTitles:(NSString *)buttonTitles, ... NS_REQUIRES_NIL_TERMINATION; 22 | 23 | // Show the alert view in current window 24 | - (void)show; 25 | 26 | // Hide the alert view 27 | - (void)hide; 28 | 29 | // Set the color and font size of title, if color is nil, default is black. if fontsize is 0, default is 14 30 | - (void)setTitleColor:(UIColor *)color fontSize:(CGFloat)size; 31 | 32 | // Set the color and font size of message, if color is nil, default is black. if fontsize is 0, default is 12 33 | - (void)setMessageColor:(UIColor *)color fontSize:(CGFloat)size; 34 | 35 | // Set the color and font size of button at the index, if color is nil, default is black. if fontsize is 0, default is 16 36 | - (void)setButtonTitleColor:(UIColor *)color fontSize:(CGFloat)size atIndex:(NSInteger)index; 37 | 38 | @end 39 | 40 | @protocol FDAlertViewDelegate 41 | 42 | - (void)alertView:(FDAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style1/FDAlertView/FDAlertView.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDAlertView.h 3 | // FDAlertViewDemo 4 | // 5 | // Created by fergusding on 15/5/26. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol FDAlertViewDelegate; 12 | 13 | @interface FDAlertView : UIView 14 | 15 | @property (strong, nonatomic) UIView *contentView; 16 | @property (strong, nonatomic) UIImage *icon; 17 | @property (strong, nonatomic) NSString *title; 18 | @property (strong, nonatomic) NSString *message; 19 | @property (weak, nonatomic) id delegate; 20 | 21 | - (instancetype)initWithTitle:(NSString *)title icon:(UIImage *)icon message:(NSString *)message delegate:(id)delegate buttonTitles:(NSString *)buttonTitles, ... NS_REQUIRES_NIL_TERMINATION; 22 | 23 | // Show the alert view in current window 24 | - (void)show; 25 | 26 | // Hide the alert view 27 | - (void)hide; 28 | 29 | // Set the color and font size of title, if color is nil, default is black. if fontsize is 0, default is 14 30 | - (void)setTitleColor:(UIColor *)color fontSize:(CGFloat)size; 31 | 32 | // Set the color and font size of message, if color is nil, default is black. if fontsize is 0, default is 12 33 | - (void)setMessageColor:(UIColor *)color fontSize:(CGFloat)size; 34 | 35 | // Set the color and font size of button at the index, if color is nil, default is black. if fontsize is 0, default is 16 36 | - (void)setButtonTitleColor:(UIColor *)color fontSize:(CGFloat)size atIndex:(NSInteger)index; 37 | 38 | @end 39 | 40 | @protocol FDAlertViewDelegate 41 | 42 | - (void)alertView:(FDAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/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 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/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 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASConstraint+Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint+Private.h 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 29/04/14. 6 | // Copyright (c) 2014 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | 11 | @protocol MASConstraintDelegate; 12 | 13 | 14 | @interface MASConstraint () 15 | 16 | /** 17 | * Whether or not to check for an existing constraint instead of adding constraint 18 | */ 19 | @property (nonatomic, assign) BOOL updateExisting; 20 | 21 | /** 22 | * Usually MASConstraintMaker but could be a parent MASConstraint 23 | */ 24 | @property (nonatomic, weak) id delegate; 25 | 26 | /** 27 | * Based on a provided value type, is equal to calling: 28 | * NSNumber - setOffset: 29 | * NSValue with CGPoint - setPointOffset: 30 | * NSValue with CGSize - setSizeOffset: 31 | * NSValue with MASEdgeInsets - setInsets: 32 | */ 33 | - (void)setLayoutConstantWithValue:(NSValue *)value; 34 | 35 | @end 36 | 37 | 38 | @interface MASConstraint (Abstract) 39 | 40 | /** 41 | * Sets the constraint relation to given NSLayoutRelation 42 | * returns a block which accepts one of the following: 43 | * MASViewAttribute, UIView, NSValue, NSArray 44 | * see readme for more details. 45 | */ 46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation; 47 | 48 | /** 49 | * Override to set a custom chaining behaviour 50 | */ 51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 52 | 53 | @end 54 | 55 | 56 | @protocol MASConstraintDelegate 57 | 58 | /** 59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example 60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks 61 | */ 62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint; 63 | 64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JGDateTimeDemo 4 | // 5 | // Created by stkcctv on 16/12/23. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/APPS/JGAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGAppDelegate.m 3 | // JGDateTime 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import "JGAppDelegate.h" 10 | #import "JGRootViewController.h" 11 | 12 | @interface JGAppDelegate () 13 | 14 | @end 15 | 16 | 17 | 18 | 19 | @implementation JGAppDelegate 20 | 21 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 22 | 23 | //创建窗口 24 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 25 | //设置窗口颜色 26 | self.window.backgroundColor = [UIColor whiteColor]; 27 | self.window.rootViewController = [[JGRootViewController alloc] init]; 28 | [self.window makeKeyAndVisible]; 29 | 30 | return YES; 31 | } 32 | 33 | - (void)applicationWillResignActive:(UIApplication *)application { 34 | // 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. 35 | // 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. 36 | } 37 | 38 | - (void)applicationDidEnterBackground:(UIApplication *)application { 39 | // 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. 40 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 41 | } 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application { 44 | // 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. 45 | } 46 | 47 | - (void)applicationDidBecomeActive:(UIApplication *)application { 48 | // 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. 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | 56 | 57 | 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/NSDate+GFCalendar.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+GFCalendar.m 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import "NSDate+GFCalendar.h" 9 | 10 | @implementation NSDate (GFCalendar) 11 | 12 | - (NSInteger)dateDay { 13 | NSCalendar *calendar = [NSCalendar currentCalendar]; 14 | NSDateComponents *components = [calendar components:NSCalendarUnitDay fromDate:self]; 15 | return components.day; 16 | } 17 | 18 | - (NSInteger)dateMonth { 19 | NSCalendar *calendar = [NSCalendar currentCalendar]; 20 | NSDateComponents *components = [calendar components:NSCalendarUnitMonth fromDate:self]; 21 | return components.month; 22 | } 23 | 24 | - (NSInteger)dateYear { 25 | NSCalendar *calendar = [NSCalendar currentCalendar]; 26 | NSDateComponents *components = [calendar components:NSCalendarUnitYear fromDate:self]; 27 | return components.year; 28 | } 29 | 30 | - (NSDate *)previousMonthDate { 31 | NSCalendar *calendar = [NSCalendar currentCalendar]; 32 | 33 | NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:self]; 34 | components.day = 15; // 定位到当月中间日子 35 | 36 | if (components.month == 1) { 37 | components.month = 12; 38 | components.year -= 1; 39 | } else { 40 | components.month -= 1; 41 | } 42 | 43 | NSDate *previousDate = [calendar dateFromComponents:components]; 44 | 45 | return previousDate; 46 | } 47 | 48 | - (NSDate *)nextMonthDate { 49 | NSCalendar *calendar = [NSCalendar currentCalendar]; 50 | 51 | NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:self]; 52 | components.day = 15; // 定位到当月中间日子 53 | 54 | if (components.month == 12) { 55 | components.month = 1; 56 | components.year += 1; 57 | } else { 58 | components.month += 1; 59 | } 60 | 61 | NSDate *nextDate = [calendar dateFromComponents:components]; 62 | 63 | return nextDate; 64 | } 65 | 66 | - (NSInteger)totalDaysInMonth { 67 | NSInteger totalDays = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:self].length; 68 | return totalDays; 69 | } 70 | 71 | - (NSInteger)firstWeekDayInMonth { 72 | NSCalendar *calendar = [NSCalendar currentCalendar]; 73 | 74 | NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:self]; 75 | components.day = 1; // 定位到当月第一天 76 | NSDate *firstDay = [calendar dateFromComponents:components]; 77 | 78 | // 默认一周第一天序号为 1 ,而日历中约定为 0 ,故需要减一 79 | NSInteger firstWeekday = [calendar ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitWeekOfMonth forDate:firstDay] - 1; 80 | 81 | return firstWeekday; 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/NSArray+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.h 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | typedef NS_ENUM(NSUInteger, MASAxisType) { 14 | MASAxisTypeHorizontal, 15 | MASAxisTypeVertical 16 | }; 17 | 18 | @interface NSArray (MASAdditions) 19 | 20 | /** 21 | * Creates a MASConstraintMaker with each view in the callee. 22 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view 23 | * 24 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 25 | * 26 | * @return Array of created MASConstraints 27 | */ 28 | - (NSArray *)mas_makeConstraints:(void (^)(MASConstraintMaker *make))block; 29 | 30 | /** 31 | * Creates a MASConstraintMaker with each view in the callee. 32 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 33 | * If an existing constraint exists then it will be updated instead. 34 | * 35 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 36 | * 37 | * @return Array of created/updated MASConstraints 38 | */ 39 | - (NSArray *)mas_updateConstraints:(void (^)(MASConstraintMaker *make))block; 40 | 41 | /** 42 | * Creates a MASConstraintMaker with each view in the callee. 43 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 44 | * All constraints previously installed for the views will be removed. 45 | * 46 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 47 | * 48 | * @return Array of created/updated MASConstraints 49 | */ 50 | - (NSArray *)mas_remakeConstraints:(void (^)(MASConstraintMaker *make))block; 51 | 52 | /** 53 | * distribute with fixed spacing 54 | * 55 | * @param axisType which axis to distribute items along 56 | * @param fixedSpacing the spacing between each item 57 | * @param leadSpacing the spacing before the first item and the container 58 | * @param tailSpacing the spacing after the last item and the container 59 | */ 60 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; 61 | 62 | /** 63 | * distribute with fixed item size 64 | * 65 | * @param axisType which axis to distribute items along 66 | * @param fixedItemLength the fixed length of each item 67 | * @param leadSpacing the spacing before the first item and the container 68 | * @param tailSpacing the spacing after the last item and the container 69 | */ 70 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style5/NYDateTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // NYDateTableViewCell.m 3 | // NYDateTimePicker 4 | // 5 | // Created by 牛严 on 15/9/24. 6 | // Copyright (c) 2015年 牛严. All rights reserved. 7 | // 8 | 9 | #import "NYDateTableViewCell.h" 10 | 11 | 12 | @interface NYDateTableViewCell () 13 | @property (strong,nonatomic) NSDateFormatter *myFomatter; 14 | @property (strong,nonatomic) NSDate *chosenDate; 15 | @end 16 | 17 | @implementation NYDateTableViewCell 18 | 19 | #pragma mark - UIView Methods 20 | - (void)awakeFromNib { 21 | [super awakeFromNib]; 22 | self.datePicker.hidden = YES; 23 | } 24 | 25 | -(void)pickerViewSetDate:(NSDate *)date{ 26 | [self.datePicker setDate:date]; 27 | } 28 | 29 | #pragma mark Private Methods 30 | -(void)reloadWithDate:(NSString *)dateString{ 31 | self.myFomatter = [[NSDateFormatter alloc]init]; 32 | [self.myFomatter setDateFormat:@"yyyy年MM月dd日"]; 33 | self.dateLabel.text = dateString; 34 | self.chosenDate = [self.myFomatter dateFromString:dateString]; 35 | } 36 | 37 | #pragma mark Animation Methods 38 | -(void)grayViewAnimation{ 39 | self.grayView.backgroundColor = [UIColor colorWithRed:208.f/255 green:208.f/255 blue:208.f/255 alpha:1.0f]; 40 | [UIView animateWithDuration:0.4 41 | animations:^{ 42 | self.grayView.backgroundColor = [UIColor clearColor]; 43 | }]; 44 | } 45 | 46 | //渐显 47 | -(void)showPickerViewAnimation{ 48 | self.dateLabel.textColor = [UIColor redColor]; 49 | self.datePicker.hidden = NO; 50 | [self.datePicker setAlpha:0]; 51 | [UIView animateWithDuration:0.2 52 | animations:^{ 53 | [self.datePicker setAlpha:1]; 54 | }]; 55 | } 56 | 57 | //渐隐 58 | -(void)fadePickerViewAnimation{ 59 | self.dateLabel.textColor = [UIColor blackColor]; 60 | [UIView animateWithDuration:0.2 61 | animations:^{ 62 | [self.datePicker setAlpha:0]; 63 | } 64 | completion:^(BOOL finished){ 65 | if (finished) { 66 | self.datePicker.hidden = YES; 67 | } 68 | }]; 69 | } 70 | 71 | #pragma mark IBAction Methods 72 | - (IBAction)datePickerValueChange:(UIDatePicker *)datePicker { 73 | NSString *dateString = [self.myFomatter stringFromDate:datePicker.date]; 74 | self.dateLabel.text = dateString; 75 | self.chosenDate = [self.myFomatter dateFromString:dateString]; 76 | [self.delegate oneDatePickerValueChanged:dateString]; 77 | } 78 | 79 | - (IBAction)setDateButtonClicked:(id)sender { 80 | [self.delegate oneDateCellHeightChange:self.ifChosen]; 81 | if (self.ifChosen == NO) { 82 | [self.datePicker setDate:self.chosenDate]; 83 | self.ifChosen = YES; 84 | [self showPickerViewAnimation]; 85 | [self grayViewAnimation]; 86 | }else{ 87 | self.ifChosen = NO; 88 | [self fadePickerViewAnimation]; 89 | [self grayViewAnimation]; 90 | } 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/View+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand view additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface MAS_VIEW (MASShorthandAdditions) 18 | 19 | @property (nonatomic, strong, readonly) MASViewAttribute *left; 20 | @property (nonatomic, strong, readonly) MASViewAttribute *top; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *right; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *width; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *height; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); 31 | 32 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 33 | 34 | @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline; 35 | @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline; 36 | 37 | #endif 38 | 39 | #if TARGET_OS_IPHONE || TARGET_OS_TV 40 | 41 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin; 42 | @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin; 43 | @property (nonatomic, strong, readonly) MASViewAttribute *topMargin; 44 | @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin; 45 | @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin; 46 | @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin; 47 | @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins; 48 | @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins; 49 | 50 | #endif 51 | 52 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 53 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 54 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 55 | 56 | @end 57 | 58 | #define MAS_ATTR_FORWARD(attr) \ 59 | - (MASViewAttribute *)attr { \ 60 | return [self mas_##attr]; \ 61 | } 62 | 63 | @implementation MAS_VIEW (MASShorthandAdditions) 64 | 65 | MAS_ATTR_FORWARD(top); 66 | MAS_ATTR_FORWARD(left); 67 | MAS_ATTR_FORWARD(bottom); 68 | MAS_ATTR_FORWARD(right); 69 | MAS_ATTR_FORWARD(leading); 70 | MAS_ATTR_FORWARD(trailing); 71 | MAS_ATTR_FORWARD(width); 72 | MAS_ATTR_FORWARD(height); 73 | MAS_ATTR_FORWARD(centerX); 74 | MAS_ATTR_FORWARD(centerY); 75 | MAS_ATTR_FORWARD(baseline); 76 | 77 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 78 | 79 | MAS_ATTR_FORWARD(firstBaseline); 80 | MAS_ATTR_FORWARD(lastBaseline); 81 | 82 | #endif 83 | 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV 85 | 86 | MAS_ATTR_FORWARD(leftMargin); 87 | MAS_ATTR_FORWARD(rightMargin); 88 | MAS_ATTR_FORWARD(topMargin); 89 | MAS_ATTR_FORWARD(bottomMargin); 90 | MAS_ATTR_FORWARD(leadingMargin); 91 | MAS_ATTR_FORWARD(trailingMargin); 92 | MAS_ATTR_FORWARD(centerXWithinMargins); 93 | MAS_ATTR_FORWARD(centerYWithinMargins); 94 | 95 | #endif 96 | 97 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute { 98 | return [self mas_attribute]; 99 | } 100 | 101 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 102 | return [self mas_makeConstraints:block]; 103 | } 104 | 105 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 106 | return [self mas_updateConstraints:block]; 107 | } 108 | 109 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 110 | return [self mas_remakeConstraints:block]; 111 | } 112 | 113 | @end 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/View+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | /** 14 | * Provides constraint maker block 15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs 16 | */ 17 | @interface MAS_VIEW (MASAdditions) 18 | 19 | /** 20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute 21 | */ 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX; 31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; 32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; 33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); 34 | 35 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 36 | 37 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline; 38 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline; 39 | 40 | #endif 41 | 42 | #if TARGET_OS_IPHONE || TARGET_OS_TV 43 | 44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin; 45 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin; 46 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin; 47 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin; 48 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin; 49 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin; 50 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins; 51 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins; 52 | 53 | #endif 54 | 55 | /** 56 | * a key to associate with this view 57 | */ 58 | @property (nonatomic, strong) id mas_key; 59 | 60 | /** 61 | * Finds the closest common superview between this view and another view 62 | * 63 | * @param view other view 64 | * 65 | * @return returns nil if common superview could not be found 66 | */ 67 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view; 68 | 69 | /** 70 | * Creates a MASConstraintMaker with the callee view. 71 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing 72 | * 73 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 74 | * 75 | * @return Array of created MASConstraints 76 | */ 77 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; 78 | 79 | /** 80 | * Creates a MASConstraintMaker with the callee view. 81 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 82 | * If an existing constraint exists then it will be updated instead. 83 | * 84 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 85 | * 86 | * @return Array of created/updated MASConstraints 87 | */ 88 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; 89 | 90 | /** 91 | * Creates a MASConstraintMaker with the callee view. 92 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 93 | * All constraints previously installed for the view will be removed. 94 | * 95 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 96 | * 97 | * @return Array of created/updated MASConstraints 98 | */ 99 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Controllers/MainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.m 3 | // NYDateTimePicker 4 | // 5 | // Created by 牛严 on 15/9/22. 6 | // Copyright (c) 2015年 牛严. All rights reserved. 7 | // 8 | 9 | #import "MainViewController.h" 10 | #import "NYDateTimeTableViewCell.h" 11 | #import "NYDateTableViewCell.h" 12 | 13 | @interface MainViewController () 14 | @property (strong, nonatomic) IBOutlet UITableView *tableView; 15 | @property (strong, nonatomic) NYDateTableViewCell *dateCell; 16 | @property (strong, nonatomic) NYDateTimeTableViewCell *timeCell; 17 | @property (strong, nonatomic) NSString *timeString; 18 | @property (strong, nonatomic) NSString *dateString; 19 | @property NSInteger timeIfChosen; 20 | @property NSInteger dateIfChosen; 21 | @end 22 | 23 | @implementation MainViewController 24 | #pragma mark Private Methods 25 | - (void)setDefaultDate{ 26 | NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; 27 | [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"]; 28 | self.timeString = [formatter stringFromDate:[NSDate date]]; 29 | [formatter setDateFormat:@"yyyy年MM月dd日"]; 30 | self.dateString = [formatter stringFromDate:[NSDate date]]; 31 | } 32 | 33 | - (void)reloadCellAnimate{ 34 | [self.tableView beginUpdates]; 35 | [self.tableView endUpdates]; 36 | } 37 | 38 | #pragma mark UIView Methods 39 | - (void)viewDidLoad { 40 | [super viewDidLoad]; 41 | 42 | self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0); 43 | 44 | self.view.backgroundColor = [UIColor whiteColor]; 45 | self.tableView.tableFooterView = [UIView new]; 46 | [self setDefaultDate]; 47 | } 48 | 49 | #pragma mark NYDateTimeDelegate 50 | - (void)oneTimeCellHeightChange:(BOOL)ifChosen{ 51 | if(!ifChosen){ 52 | self.timeIfChosen = 1; 53 | //缩回其他cell 54 | [self shrinkDatePickerCell]; 55 | }else{ 56 | self.timeIfChosen = 0; 57 | } 58 | [self reloadCellAnimate]; 59 | } 60 | 61 | - (void)oneTimePickerValueChanged:(NSString *)dateString{ 62 | self.timeString = dateString; 63 | } 64 | 65 | #pragma mark NYDateDelegate 66 | -(void)oneDatePickerValueChanged:(NSString *)dateString{ 67 | self.dateString = dateString; 68 | } 69 | 70 | -(void)oneDateCellHeightChange:(BOOL)ifChosen{ 71 | if (!ifChosen) { 72 | self.dateIfChosen = 1; 73 | [self shrinkDateTimePickerCell]; 74 | }else{ 75 | self.dateIfChosen = 0; 76 | } 77 | [self reloadCellAnimate]; 78 | } 79 | 80 | 81 | #pragma mark 改变cell高度方法,在beginupdates endupdates中使用 82 | -(void)shrinkDateTimePickerCell{ 83 | self.timeIfChosen = 0; 84 | [self.timeCell fadePickerViewAnimation]; 85 | self.timeCell.ifChosen = NO; 86 | } 87 | 88 | -(void)shrinkDatePickerCell{ 89 | self.dateIfChosen = 0; 90 | [self.dateCell fadePickerViewAnimation]; 91 | self.dateCell.ifChosen = NO; 92 | } 93 | 94 | #pragma mark - Table View Data Source 95 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 96 | return 2; 97 | } 98 | 99 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 100 | switch (indexPath.row) { 101 | case 0:{ 102 | self.timeCell = [tableView dequeueReusableCellWithIdentifier:@"NYDateTimeTableViewCell"]; 103 | self.timeCell = [[[NSBundle mainBundle] loadNibNamed:@"NYDateTimeTableViewCell" owner:self options:nil]lastObject]; 104 | self.timeCell.delegate = self; 105 | [self.timeCell reloadWithDate:self.timeString]; 106 | return self.timeCell; 107 | } 108 | break; 109 | 110 | case 1:{ 111 | self.dateCell = [tableView dequeueReusableCellWithIdentifier:@"NYDateTableViewCell"]; 112 | self.dateCell = [[[NSBundle mainBundle] loadNibNamed:@"NYDateTableViewCell" owner:self options:nil]lastObject]; 113 | self.dateCell.delegate = self; 114 | [self.dateCell reloadWithDate:self.dateString]; 115 | return self.dateCell; 116 | } 117 | break; 118 | } 119 | return nil; 120 | } 121 | 122 | #pragma mark - Table View Delegate 123 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 124 | { 125 | if(indexPath.row == 0){ 126 | if (self.timeIfChosen != 0) return 235.f; 127 | } 128 | if(indexPath.row == 1){ 129 | if (self.dateIfChosen != 0) return 235.f; 130 | } 131 | return 40.f; 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Controllers/MainViewController.xib: -------------------------------------------------------------------------------- 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 | 30 | 31 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASCompositeConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASCompositeConstraint.h" 10 | #import "MASConstraint+Private.h" 11 | 12 | @interface MASCompositeConstraint () 13 | 14 | @property (nonatomic, strong) id mas_key; 15 | @property (nonatomic, strong) NSMutableArray *childConstraints; 16 | 17 | @end 18 | 19 | @implementation MASCompositeConstraint 20 | 21 | - (id)initWithChildren:(NSArray *)children { 22 | self = [super init]; 23 | if (!self) return nil; 24 | 25 | _childConstraints = [children mutableCopy]; 26 | for (MASConstraint *constraint in _childConstraints) { 27 | constraint.delegate = self; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | #pragma mark - MASConstraintDelegate 34 | 35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 36 | NSUInteger index = [self.childConstraints indexOfObject:constraint]; 37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint]; 39 | } 40 | 41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 42 | id strongDelegate = self.delegate; 43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 44 | newConstraint.delegate = self; 45 | [self.childConstraints addObject:newConstraint]; 46 | return newConstraint; 47 | } 48 | 49 | #pragma mark - NSLayoutConstraint multiplier proxies 50 | 51 | - (MASConstraint * (^)(CGFloat))multipliedBy { 52 | return ^id(CGFloat multiplier) { 53 | for (MASConstraint *constraint in self.childConstraints) { 54 | constraint.multipliedBy(multiplier); 55 | } 56 | return self; 57 | }; 58 | } 59 | 60 | - (MASConstraint * (^)(CGFloat))dividedBy { 61 | return ^id(CGFloat divider) { 62 | for (MASConstraint *constraint in self.childConstraints) { 63 | constraint.dividedBy(divider); 64 | } 65 | return self; 66 | }; 67 | } 68 | 69 | #pragma mark - MASLayoutPriority proxy 70 | 71 | - (MASConstraint * (^)(MASLayoutPriority))priority { 72 | return ^id(MASLayoutPriority priority) { 73 | for (MASConstraint *constraint in self.childConstraints) { 74 | constraint.priority(priority); 75 | } 76 | return self; 77 | }; 78 | } 79 | 80 | #pragma mark - NSLayoutRelation proxy 81 | 82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { 83 | return ^id(id attr, NSLayoutRelation relation) { 84 | for (MASConstraint *constraint in self.childConstraints.copy) { 85 | constraint.equalToWithRelation(attr, relation); 86 | } 87 | return self; 88 | }; 89 | } 90 | 91 | #pragma mark - attribute chaining 92 | 93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 95 | return self; 96 | } 97 | 98 | #pragma mark - Animator proxy 99 | 100 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 101 | 102 | - (MASConstraint *)animator { 103 | for (MASConstraint *constraint in self.childConstraints) { 104 | [constraint animator]; 105 | } 106 | return self; 107 | } 108 | 109 | #endif 110 | 111 | #pragma mark - debug helpers 112 | 113 | - (MASConstraint * (^)(id))key { 114 | return ^id(id key) { 115 | self.mas_key = key; 116 | int i = 0; 117 | for (MASConstraint *constraint in self.childConstraints) { 118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]); 119 | } 120 | return self; 121 | }; 122 | } 123 | 124 | #pragma mark - NSLayoutConstraint constant setters 125 | 126 | - (void)setInsets:(MASEdgeInsets)insets { 127 | for (MASConstraint *constraint in self.childConstraints) { 128 | constraint.insets = insets; 129 | } 130 | } 131 | 132 | - (void)setOffset:(CGFloat)offset { 133 | for (MASConstraint *constraint in self.childConstraints) { 134 | constraint.offset = offset; 135 | } 136 | } 137 | 138 | - (void)setSizeOffset:(CGSize)sizeOffset { 139 | for (MASConstraint *constraint in self.childConstraints) { 140 | constraint.sizeOffset = sizeOffset; 141 | } 142 | } 143 | 144 | - (void)setCenterOffset:(CGPoint)centerOffset { 145 | for (MASConstraint *constraint in self.childConstraints) { 146 | constraint.centerOffset = centerOffset; 147 | } 148 | } 149 | 150 | #pragma mark - MASConstraint 151 | 152 | - (void)activate { 153 | for (MASConstraint *constraint in self.childConstraints) { 154 | [constraint activate]; 155 | } 156 | } 157 | 158 | - (void)deactivate { 159 | for (MASConstraint *constraint in self.childConstraints) { 160 | [constraint deactivate]; 161 | } 162 | } 163 | 164 | - (void)install { 165 | for (MASConstraint *constraint in self.childConstraints) { 166 | constraint.updateExisting = self.updateExisting; 167 | [constraint install]; 168 | } 169 | } 170 | 171 | - (void)uninstall { 172 | for (MASConstraint *constraint in self.childConstraints) { 173 | [constraint uninstall]; 174 | } 175 | } 176 | 177 | @end 178 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style3/GFCalendar/GFCalendarView.m: -------------------------------------------------------------------------------- 1 | // 2 | // GFCalendarView.m 3 | // 4 | // Created by Mercy on 2016/11/9. 5 | // Copyright © 2016年 Mercy. All rights reserved. 6 | // 7 | 8 | #import "GFCalendarView.h" 9 | #import "GFCalendarScrollView.h" 10 | #import "NSDate+GFCalendar.h" 11 | 12 | @interface GFCalendarView() 13 | 14 | @property (nonatomic, strong) UIButton *calendarHeaderButton; 15 | @property (nonatomic, strong) UIView *weekHeaderView; 16 | @property (nonatomic, strong) GFCalendarScrollView *calendarScrollView; 17 | 18 | @end 19 | 20 | #define kCalendarBasicColor [UIColor colorWithRed:231.0 / 255.0 green:85.0 / 255.0 blue:85.0 / 255.0 alpha:1.0] 21 | //#define kCalendarBasicColor [UIColor colorWithRed:252.0 / 255.0 green:60.0 / 255.0 blue:60.0 / 255.0 alpha:1.0] 22 | 23 | @implementation GFCalendarView 24 | 25 | 26 | #pragma mark - Initialization 27 | 28 | - (instancetype)initWithFrameOrigin:(CGPoint)origin width:(CGFloat)width { 29 | 30 | // 根据宽度计算 calender 主体部分的高度 31 | CGFloat weekLineHight = 0.85 * (width / 7.0); 32 | CGFloat monthHeight = 6 * weekLineHight; 33 | 34 | // 星期头部栏高度 35 | CGFloat weekHeaderHeight = 0.6 * weekLineHight; 36 | 37 | // calendar 头部栏高度 38 | CGFloat calendarHeaderHeight = 0.8 * weekLineHight; 39 | 40 | // 最后得到整个 calender 控件的高度 41 | _calendarHeight = calendarHeaderHeight + weekHeaderHeight + monthHeight; 42 | 43 | if (self = [super initWithFrame:CGRectMake(origin.x, origin.y, width, _calendarHeight)]) { 44 | 45 | self.layer.masksToBounds = YES; 46 | self.layer.borderColor = kCalendarBasicColor.CGColor; 47 | self.layer.borderWidth = 2.0 / [UIScreen mainScreen].scale; 48 | self.layer.cornerRadius = 8.0; 49 | 50 | _calendarHeaderButton = [self setupCalendarHeaderButtonWithFrame:CGRectMake(0.0, 0.0, width, calendarHeaderHeight)]; 51 | _weekHeaderView = [self setupWeekHeadViewWithFrame:CGRectMake(0.0, calendarHeaderHeight, width, weekHeaderHeight)]; 52 | _calendarScrollView = [self setupCalendarScrollViewWithFrame:CGRectMake(0.0, calendarHeaderHeight + weekHeaderHeight, width, monthHeight)]; 53 | 54 | [self addSubview:_calendarHeaderButton]; 55 | [self addSubview:_weekHeaderView]; 56 | [self addSubview:_calendarScrollView]; 57 | 58 | // 注册 Notification 监听 59 | [self addNotificationObserver]; 60 | 61 | } 62 | 63 | return self; 64 | 65 | } 66 | 67 | - (void)dealloc { 68 | // 移除监听 69 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 70 | } 71 | 72 | - (UIButton *)setupCalendarHeaderButtonWithFrame:(CGRect)frame { 73 | 74 | UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 75 | button.frame = frame; 76 | button.backgroundColor = kCalendarBasicColor; 77 | [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 78 | button.titleLabel.font = [UIFont systemFontOfSize:16.0]; 79 | [button addTarget:self action:@selector(refreshToCurrentMonthAction:) forControlEvents:UIControlEventTouchUpInside]; 80 | 81 | return button; 82 | } 83 | 84 | - (UIView *)setupWeekHeadViewWithFrame:(CGRect)frame { 85 | 86 | CGFloat height = frame.size.height; 87 | CGFloat width = frame.size.width / 7.0; 88 | 89 | UIView *view = [[UIView alloc] initWithFrame:frame]; 90 | view.backgroundColor = kCalendarBasicColor; 91 | 92 | NSArray *weekArray = @[@"日", @"一", @"二", @"三", @"四", @"五", @"六"]; 93 | for (int i = 0; i < 7; ++i) { 94 | 95 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(i * width, 0.0, width, height)]; 96 | label.backgroundColor = [UIColor clearColor]; 97 | label.text = weekArray[i]; 98 | label.textColor = [UIColor whiteColor]; 99 | label.font = [UIFont systemFontOfSize:13.5]; 100 | label.textAlignment = NSTextAlignmentCenter; 101 | [view addSubview:label]; 102 | 103 | } 104 | 105 | return view; 106 | 107 | } 108 | 109 | - (GFCalendarScrollView *)setupCalendarScrollViewWithFrame:(CGRect)frame { 110 | GFCalendarScrollView *scrollView = [[GFCalendarScrollView alloc] initWithFrame:frame]; 111 | return scrollView; 112 | } 113 | 114 | - (void)setDidSelectDayHandler:(DidSelectDayHandler)didSelectDayHandler { 115 | _didSelectDayHandler = didSelectDayHandler; 116 | if (_calendarScrollView != nil) { 117 | _calendarScrollView.didSelectDayHandler = _didSelectDayHandler; // 传递 block 118 | } 119 | } 120 | 121 | - (void)addNotificationObserver { 122 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeCalendarHeaderAction:) name:@"ChangeCalendarHeaderNotification" object:nil]; 123 | } 124 | 125 | 126 | #pragma mark - Actions 127 | 128 | - (void)refreshToCurrentMonthAction:(UIButton *)sender { 129 | 130 | NSInteger year = [[NSDate date] dateYear]; 131 | NSInteger month = [[NSDate date] dateMonth]; 132 | 133 | NSString *title = [NSString stringWithFormat:@"%ld年%ld月", year, month]; 134 | 135 | [_calendarHeaderButton setTitle:title forState:UIControlStateNormal]; 136 | 137 | [_calendarScrollView refreshToCurrentMonth]; 138 | 139 | } 140 | 141 | - (void)changeCalendarHeaderAction:(NSNotification *)sender { 142 | 143 | NSDictionary *dic = sender.userInfo; 144 | 145 | NSNumber *year = dic[@"year"]; 146 | NSNumber *month = dic[@"month"]; 147 | 148 | NSString *title = [NSString stringWithFormat:@"%@年%@月", year, month]; 149 | 150 | [_calendarHeaderButton setTitle:title forState:UIControlStateNormal]; 151 | } 152 | 153 | @end 154 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASConstraintMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | typedef NS_OPTIONS(NSInteger, MASAttribute) { 13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft, 14 | MASAttributeRight = 1 << NSLayoutAttributeRight, 15 | MASAttributeTop = 1 << NSLayoutAttributeTop, 16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom, 17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading, 18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing, 19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth, 20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight, 21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX, 22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, 23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, 24 | 25 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 26 | 27 | MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline, 28 | MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline, 29 | 30 | #endif 31 | 32 | #if TARGET_OS_IPHONE || TARGET_OS_TV 33 | 34 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin, 35 | MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin, 36 | MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin, 37 | MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin, 38 | MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin, 39 | MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin, 40 | MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins, 41 | MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins, 42 | 43 | #endif 44 | 45 | }; 46 | 47 | /** 48 | * Provides factory methods for creating MASConstraints. 49 | * Constraints are collected until they are ready to be installed 50 | * 51 | */ 52 | @interface MASConstraintMaker : NSObject 53 | 54 | /** 55 | * The following properties return a new MASViewConstraint 56 | * with the first item set to the makers associated view and the appropriate MASViewAttribute 57 | */ 58 | @property (nonatomic, strong, readonly) MASConstraint *left; 59 | @property (nonatomic, strong, readonly) MASConstraint *top; 60 | @property (nonatomic, strong, readonly) MASConstraint *right; 61 | @property (nonatomic, strong, readonly) MASConstraint *bottom; 62 | @property (nonatomic, strong, readonly) MASConstraint *leading; 63 | @property (nonatomic, strong, readonly) MASConstraint *trailing; 64 | @property (nonatomic, strong, readonly) MASConstraint *width; 65 | @property (nonatomic, strong, readonly) MASConstraint *height; 66 | @property (nonatomic, strong, readonly) MASConstraint *centerX; 67 | @property (nonatomic, strong, readonly) MASConstraint *centerY; 68 | @property (nonatomic, strong, readonly) MASConstraint *baseline; 69 | 70 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 71 | 72 | @property (nonatomic, strong, readonly) MASConstraint *firstBaseline; 73 | @property (nonatomic, strong, readonly) MASConstraint *lastBaseline; 74 | 75 | #endif 76 | 77 | #if TARGET_OS_IPHONE || TARGET_OS_TV 78 | 79 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin; 80 | @property (nonatomic, strong, readonly) MASConstraint *rightMargin; 81 | @property (nonatomic, strong, readonly) MASConstraint *topMargin; 82 | @property (nonatomic, strong, readonly) MASConstraint *bottomMargin; 83 | @property (nonatomic, strong, readonly) MASConstraint *leadingMargin; 84 | @property (nonatomic, strong, readonly) MASConstraint *trailingMargin; 85 | @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins; 86 | @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins; 87 | 88 | #endif 89 | 90 | /** 91 | * Returns a block which creates a new MASCompositeConstraint with the first item set 92 | * to the makers associated view and children corresponding to the set bits in the 93 | * MASAttribute parameter. Combine multiple attributes via binary-or. 94 | */ 95 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs); 96 | 97 | /** 98 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges 99 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right) 100 | * with the first item set to the makers associated view 101 | */ 102 | @property (nonatomic, strong, readonly) MASConstraint *edges; 103 | 104 | /** 105 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize 106 | * which generates the appropriate MASViewConstraint children (width, height) 107 | * with the first item set to the makers associated view 108 | */ 109 | @property (nonatomic, strong, readonly) MASConstraint *size; 110 | 111 | /** 112 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter 113 | * which generates the appropriate MASViewConstraint children (centerX, centerY) 114 | * with the first item set to the makers associated view 115 | */ 116 | @property (nonatomic, strong, readonly) MASConstraint *center; 117 | 118 | /** 119 | * Whether or not to check for an existing constraint instead of adding constraint 120 | */ 121 | @property (nonatomic, assign) BOOL updateExisting; 122 | 123 | /** 124 | * Whether or not to remove existing constraints prior to installing 125 | */ 126 | @property (nonatomic, assign) BOOL removeExisting; 127 | 128 | /** 129 | * initialises the maker with a default view 130 | * 131 | * @param view any MASConstrait are created with this view as the first item 132 | * 133 | * @return a new MASConstraintMaker 134 | */ 135 | - (id)initWithView:(MAS_VIEW *)view; 136 | 137 | /** 138 | * Calls install method on any MASConstraints which have been created by this maker 139 | * 140 | * @return an array of all the installed MASConstraints 141 | */ 142 | - (NSArray *)install; 143 | 144 | - (MASConstraint * (^)(dispatch_block_t))group; 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/View+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | #import 11 | 12 | @implementation MAS_VIEW (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block { 15 | self.translatesAutoresizingMaskIntoConstraints = NO; 16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 17 | block(constraintMaker); 18 | return [constraintMaker install]; 19 | } 20 | 21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { 22 | self.translatesAutoresizingMaskIntoConstraints = NO; 23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 24 | constraintMaker.updateExisting = YES; 25 | block(constraintMaker); 26 | return [constraintMaker install]; 27 | } 28 | 29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 30 | self.translatesAutoresizingMaskIntoConstraints = NO; 31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 32 | constraintMaker.removeExisting = YES; 33 | block(constraintMaker); 34 | return [constraintMaker install]; 35 | } 36 | 37 | #pragma mark - NSLayoutAttribute properties 38 | 39 | - (MASViewAttribute *)mas_left { 40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft]; 41 | } 42 | 43 | - (MASViewAttribute *)mas_top { 44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop]; 45 | } 46 | 47 | - (MASViewAttribute *)mas_right { 48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight]; 49 | } 50 | 51 | - (MASViewAttribute *)mas_bottom { 52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom]; 53 | } 54 | 55 | - (MASViewAttribute *)mas_leading { 56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading]; 57 | } 58 | 59 | - (MASViewAttribute *)mas_trailing { 60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing]; 61 | } 62 | 63 | - (MASViewAttribute *)mas_width { 64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth]; 65 | } 66 | 67 | - (MASViewAttribute *)mas_height { 68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight]; 69 | } 70 | 71 | - (MASViewAttribute *)mas_centerX { 72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX]; 73 | } 74 | 75 | - (MASViewAttribute *)mas_centerY { 76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY]; 77 | } 78 | 79 | - (MASViewAttribute *)mas_baseline { 80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline]; 81 | } 82 | 83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute 84 | { 85 | return ^(NSLayoutAttribute attr) { 86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr]; 87 | }; 88 | } 89 | 90 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 91 | 92 | - (MASViewAttribute *)mas_firstBaseline { 93 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeFirstBaseline]; 94 | } 95 | - (MASViewAttribute *)mas_lastBaseline { 96 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline]; 97 | } 98 | 99 | #endif 100 | 101 | #if TARGET_OS_IPHONE || TARGET_OS_TV 102 | 103 | - (MASViewAttribute *)mas_leftMargin { 104 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin]; 105 | } 106 | 107 | - (MASViewAttribute *)mas_rightMargin { 108 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin]; 109 | } 110 | 111 | - (MASViewAttribute *)mas_topMargin { 112 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin]; 113 | } 114 | 115 | - (MASViewAttribute *)mas_bottomMargin { 116 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin]; 117 | } 118 | 119 | - (MASViewAttribute *)mas_leadingMargin { 120 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin]; 121 | } 122 | 123 | - (MASViewAttribute *)mas_trailingMargin { 124 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin]; 125 | } 126 | 127 | - (MASViewAttribute *)mas_centerXWithinMargins { 128 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 129 | } 130 | 131 | - (MASViewAttribute *)mas_centerYWithinMargins { 132 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 133 | } 134 | 135 | #endif 136 | 137 | #pragma mark - associated properties 138 | 139 | - (id)mas_key { 140 | return objc_getAssociatedObject(self, @selector(mas_key)); 141 | } 142 | 143 | - (void)setMas_key:(id)key { 144 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 145 | } 146 | 147 | #pragma mark - heirachy 148 | 149 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view { 150 | MAS_VIEW *closestCommonSuperview = nil; 151 | 152 | MAS_VIEW *secondViewSuperview = view; 153 | while (!closestCommonSuperview && secondViewSuperview) { 154 | MAS_VIEW *firstViewSuperview = self; 155 | while (!closestCommonSuperview && firstViewSuperview) { 156 | if (secondViewSuperview == firstViewSuperview) { 157 | closestCommonSuperview = secondViewSuperview; 158 | } 159 | firstViewSuperview = firstViewSuperview.superview; 160 | } 161 | secondViewSuperview = secondViewSuperview.superview; 162 | } 163 | return closestCommonSuperview; 164 | } 165 | 166 | @end 167 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/NSLayoutConstraint+MASDebugAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSLayoutConstraint+MASDebugAdditions.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | 13 | @implementation NSLayoutConstraint (MASDebugAdditions) 14 | 15 | #pragma mark - description maps 16 | 17 | + (NSDictionary *)layoutRelationDescriptionsByValue { 18 | static dispatch_once_t once; 19 | static NSDictionary *descriptionMap; 20 | dispatch_once(&once, ^{ 21 | descriptionMap = @{ 22 | @(NSLayoutRelationEqual) : @"==", 23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=", 24 | @(NSLayoutRelationLessThanOrEqual) : @"<=", 25 | }; 26 | }); 27 | return descriptionMap; 28 | } 29 | 30 | + (NSDictionary *)layoutAttributeDescriptionsByValue { 31 | static dispatch_once_t once; 32 | static NSDictionary *descriptionMap; 33 | dispatch_once(&once, ^{ 34 | descriptionMap = @{ 35 | @(NSLayoutAttributeTop) : @"top", 36 | @(NSLayoutAttributeLeft) : @"left", 37 | @(NSLayoutAttributeBottom) : @"bottom", 38 | @(NSLayoutAttributeRight) : @"right", 39 | @(NSLayoutAttributeLeading) : @"leading", 40 | @(NSLayoutAttributeTrailing) : @"trailing", 41 | @(NSLayoutAttributeWidth) : @"width", 42 | @(NSLayoutAttributeHeight) : @"height", 43 | @(NSLayoutAttributeCenterX) : @"centerX", 44 | @(NSLayoutAttributeCenterY) : @"centerY", 45 | @(NSLayoutAttributeBaseline) : @"baseline", 46 | 47 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 48 | @(NSLayoutAttributeFirstBaseline) : @"firstBaseline", 49 | @(NSLayoutAttributeLastBaseline) : @"lastBaseline", 50 | #endif 51 | 52 | #if TARGET_OS_IPHONE || TARGET_OS_TV 53 | @(NSLayoutAttributeLeftMargin) : @"leftMargin", 54 | @(NSLayoutAttributeRightMargin) : @"rightMargin", 55 | @(NSLayoutAttributeTopMargin) : @"topMargin", 56 | @(NSLayoutAttributeBottomMargin) : @"bottomMargin", 57 | @(NSLayoutAttributeLeadingMargin) : @"leadingMargin", 58 | @(NSLayoutAttributeTrailingMargin) : @"trailingMargin", 59 | @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins", 60 | @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins", 61 | #endif 62 | 63 | }; 64 | 65 | }); 66 | return descriptionMap; 67 | } 68 | 69 | 70 | + (NSDictionary *)layoutPriorityDescriptionsByValue { 71 | static dispatch_once_t once; 72 | static NSDictionary *descriptionMap; 73 | dispatch_once(&once, ^{ 74 | #if TARGET_OS_IPHONE || TARGET_OS_TV 75 | descriptionMap = @{ 76 | @(MASLayoutPriorityDefaultHigh) : @"high", 77 | @(MASLayoutPriorityDefaultLow) : @"low", 78 | @(MASLayoutPriorityDefaultMedium) : @"medium", 79 | @(MASLayoutPriorityRequired) : @"required", 80 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size", 81 | }; 82 | #elif TARGET_OS_MAC 83 | descriptionMap = @{ 84 | @(MASLayoutPriorityDefaultHigh) : @"high", 85 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window", 86 | @(MASLayoutPriorityDefaultMedium) : @"medium", 87 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put", 88 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window", 89 | @(MASLayoutPriorityDefaultLow) : @"low", 90 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size", 91 | @(MASLayoutPriorityRequired) : @"required", 92 | }; 93 | #endif 94 | }); 95 | return descriptionMap; 96 | } 97 | 98 | #pragma mark - description override 99 | 100 | + (NSString *)descriptionForObject:(id)obj { 101 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) { 102 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]]; 103 | } 104 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj]; 105 | } 106 | 107 | - (NSString *)description { 108 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"]; 109 | 110 | [description appendString:[self.class descriptionForObject:self]]; 111 | 112 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]]; 113 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) { 114 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.firstAttribute)]]; 115 | } 116 | 117 | [description appendFormat:@" %@", self.class.layoutRelationDescriptionsByValue[@(self.relation)]]; 118 | 119 | if (self.secondItem) { 120 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]]; 121 | } 122 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) { 123 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.secondAttribute)]]; 124 | } 125 | 126 | if (self.multiplier != 1) { 127 | [description appendFormat:@" * %g", self.multiplier]; 128 | } 129 | 130 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) { 131 | [description appendFormat:@" %g", self.constant]; 132 | } else { 133 | if (self.constant) { 134 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)]; 135 | } 136 | } 137 | 138 | if (self.priority != MASLayoutPriorityRequired) { 139 | [description appendFormat:@" ^%@", self.class.layoutPriorityDescriptionsByValue[@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]]; 140 | } 141 | 142 | [description appendString:@">"]; 143 | return description; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASUtilities.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 19/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | 13 | #if TARGET_OS_IPHONE || TARGET_OS_TV 14 | 15 | #import 16 | #define MAS_VIEW UIView 17 | #define MAS_VIEW_CONTROLLER UIViewController 18 | #define MASEdgeInsets UIEdgeInsets 19 | 20 | typedef UILayoutPriority MASLayoutPriority; 21 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired; 22 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh; 23 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500; 24 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow; 25 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel; 26 | 27 | #elif TARGET_OS_MAC 28 | 29 | #import 30 | #define MAS_VIEW NSView 31 | #define MASEdgeInsets NSEdgeInsets 32 | 33 | typedef NSLayoutPriority MASLayoutPriority; 34 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired; 35 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh; 36 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow; 37 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501; 38 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut; 39 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow; 40 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow; 41 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression; 42 | 43 | #endif 44 | 45 | /** 46 | * Allows you to attach keys to objects matching the variable names passed. 47 | * 48 | * view1.mas_key = @"view1", view2.mas_key = @"view2"; 49 | * 50 | * is equivalent to: 51 | * 52 | * MASAttachKeys(view1, view2); 53 | */ 54 | #define MASAttachKeys(...) \ 55 | { \ 56 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \ 57 | for (id key in keyPairs.allKeys) { \ 58 | id obj = keyPairs[key]; \ 59 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \ 60 | @"Cannot attach mas_key to %@", obj); \ 61 | [obj setMas_key:key]; \ 62 | } \ 63 | } 64 | 65 | /** 66 | * Used to create object hashes 67 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html 68 | */ 69 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger)) 70 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch))) 71 | 72 | /** 73 | * Given a scalar or struct value, wraps it in NSValue 74 | * Based on EXPObjectify: https://github.com/specta/expecta 75 | */ 76 | static inline id _MASBoxValue(const char *type, ...) { 77 | va_list v; 78 | va_start(v, type); 79 | id obj = nil; 80 | if (strcmp(type, @encode(id)) == 0) { 81 | id actual = va_arg(v, id); 82 | obj = actual; 83 | } else if (strcmp(type, @encode(CGPoint)) == 0) { 84 | CGPoint actual = (CGPoint)va_arg(v, CGPoint); 85 | obj = [NSValue value:&actual withObjCType:type]; 86 | } else if (strcmp(type, @encode(CGSize)) == 0) { 87 | CGSize actual = (CGSize)va_arg(v, CGSize); 88 | obj = [NSValue value:&actual withObjCType:type]; 89 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { 90 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); 91 | obj = [NSValue value:&actual withObjCType:type]; 92 | } else if (strcmp(type, @encode(double)) == 0) { 93 | double actual = (double)va_arg(v, double); 94 | obj = [NSNumber numberWithDouble:actual]; 95 | } else if (strcmp(type, @encode(float)) == 0) { 96 | float actual = (float)va_arg(v, double); 97 | obj = [NSNumber numberWithFloat:actual]; 98 | } else if (strcmp(type, @encode(int)) == 0) { 99 | int actual = (int)va_arg(v, int); 100 | obj = [NSNumber numberWithInt:actual]; 101 | } else if (strcmp(type, @encode(long)) == 0) { 102 | long actual = (long)va_arg(v, long); 103 | obj = [NSNumber numberWithLong:actual]; 104 | } else if (strcmp(type, @encode(long long)) == 0) { 105 | long long actual = (long long)va_arg(v, long long); 106 | obj = [NSNumber numberWithLongLong:actual]; 107 | } else if (strcmp(type, @encode(short)) == 0) { 108 | short actual = (short)va_arg(v, int); 109 | obj = [NSNumber numberWithShort:actual]; 110 | } else if (strcmp(type, @encode(char)) == 0) { 111 | char actual = (char)va_arg(v, int); 112 | obj = [NSNumber numberWithChar:actual]; 113 | } else if (strcmp(type, @encode(bool)) == 0) { 114 | bool actual = (bool)va_arg(v, int); 115 | obj = [NSNumber numberWithBool:actual]; 116 | } else if (strcmp(type, @encode(unsigned char)) == 0) { 117 | unsigned char actual = (unsigned char)va_arg(v, unsigned int); 118 | obj = [NSNumber numberWithUnsignedChar:actual]; 119 | } else if (strcmp(type, @encode(unsigned int)) == 0) { 120 | unsigned int actual = (unsigned int)va_arg(v, unsigned int); 121 | obj = [NSNumber numberWithUnsignedInt:actual]; 122 | } else if (strcmp(type, @encode(unsigned long)) == 0) { 123 | unsigned long actual = (unsigned long)va_arg(v, unsigned long); 124 | obj = [NSNumber numberWithUnsignedLong:actual]; 125 | } else if (strcmp(type, @encode(unsigned long long)) == 0) { 126 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); 127 | obj = [NSNumber numberWithUnsignedLongLong:actual]; 128 | } else if (strcmp(type, @encode(unsigned short)) == 0) { 129 | unsigned short actual = (unsigned short)va_arg(v, unsigned int); 130 | obj = [NSNumber numberWithUnsignedShort:actual]; 131 | } 132 | va_end(v); 133 | return obj; 134 | } 135 | 136 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) 137 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/NSArray+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.m 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | #import "View+MASAdditions.h" 11 | 12 | @implementation NSArray (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { 15 | NSMutableArray *constraints = [NSMutableArray array]; 16 | for (MAS_VIEW *view in self) { 17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]]; 19 | } 20 | return constraints; 21 | } 22 | 23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { 24 | NSMutableArray *constraints = [NSMutableArray array]; 25 | for (MAS_VIEW *view in self) { 26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]]; 28 | } 29 | return constraints; 30 | } 31 | 32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 33 | NSMutableArray *constraints = [NSMutableArray array]; 34 | for (MAS_VIEW *view in self) { 35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]]; 37 | } 38 | return constraints; 39 | } 40 | 41 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing { 42 | if (self.count < 2) { 43 | NSAssert(self.count>1,@"views to distribute need to bigger than one"); 44 | return; 45 | } 46 | 47 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews]; 48 | if (axisType == MASAxisTypeHorizontal) { 49 | MAS_VIEW *prev; 50 | for (int i = 0; i < self.count; i++) { 51 | MAS_VIEW *v = self[i]; 52 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 53 | if (prev) { 54 | make.width.equalTo(prev); 55 | make.left.equalTo(prev.mas_right).offset(fixedSpacing); 56 | if (i == self.count - 1) {//last one 57 | make.right.equalTo(tempSuperView).offset(-tailSpacing); 58 | } 59 | } 60 | else {//first one 61 | make.left.equalTo(tempSuperView).offset(leadSpacing); 62 | } 63 | 64 | }]; 65 | prev = v; 66 | } 67 | } 68 | else { 69 | MAS_VIEW *prev; 70 | for (int i = 0; i < self.count; i++) { 71 | MAS_VIEW *v = self[i]; 72 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 73 | if (prev) { 74 | make.height.equalTo(prev); 75 | make.top.equalTo(prev.mas_bottom).offset(fixedSpacing); 76 | if (i == self.count - 1) {//last one 77 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); 78 | } 79 | } 80 | else {//first one 81 | make.top.equalTo(tempSuperView).offset(leadSpacing); 82 | } 83 | 84 | }]; 85 | prev = v; 86 | } 87 | } 88 | } 89 | 90 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing { 91 | if (self.count < 2) { 92 | NSAssert(self.count>1,@"views to distribute need to bigger than one"); 93 | return; 94 | } 95 | 96 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews]; 97 | if (axisType == MASAxisTypeHorizontal) { 98 | MAS_VIEW *prev; 99 | for (int i = 0; i < self.count; i++) { 100 | MAS_VIEW *v = self[i]; 101 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 102 | make.width.equalTo(@(fixedItemLength)); 103 | if (prev) { 104 | if (i == self.count - 1) {//last one 105 | make.right.equalTo(tempSuperView).offset(-tailSpacing); 106 | } 107 | else { 108 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); 109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); 110 | } 111 | } 112 | else {//first one 113 | make.left.equalTo(tempSuperView).offset(leadSpacing); 114 | } 115 | }]; 116 | prev = v; 117 | } 118 | } 119 | else { 120 | MAS_VIEW *prev; 121 | for (int i = 0; i < self.count; i++) { 122 | MAS_VIEW *v = self[i]; 123 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 124 | make.height.equalTo(@(fixedItemLength)); 125 | if (prev) { 126 | if (i == self.count - 1) {//last one 127 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); 128 | } 129 | else { 130 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); 131 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); 132 | } 133 | } 134 | else {//first one 135 | make.top.equalTo(tempSuperView).offset(leadSpacing); 136 | } 137 | }]; 138 | prev = v; 139 | } 140 | } 141 | } 142 | 143 | - (MAS_VIEW *)mas_commonSuperviewOfViews 144 | { 145 | MAS_VIEW *commonSuperview = nil; 146 | MAS_VIEW *previousView = nil; 147 | for (id object in self) { 148 | if ([object isKindOfClass:[MAS_VIEW class]]) { 149 | MAS_VIEW *view = (MAS_VIEW *)object; 150 | if (previousView) { 151 | commonSuperview = [view mas_closestCommonSuperview:commonSuperview]; 152 | } else { 153 | commonSuperview = view; 154 | } 155 | previousView = view; 156 | } 157 | } 158 | NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); 159 | return commonSuperview; 160 | } 161 | 162 | @end 163 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTimeDemo/JGDateTimeDemo/CycleScollview/MXSCycleScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MXSCycleScrollView.m 3 | // xuexin 4 | // e-mail:rbyyy924805@163.com 5 | // Created by renbing on 3/7/14. 6 | // Copyright (c) 2014 renbing. All rights reserved. 7 | // 8 | 9 | #import "MXSCycleScrollView.h" 10 | #define RGBA(r,g,b,a) [UIColor colorWithRed:(float)r/255.0f green:(float)g/255.0f blue:(float)b/255.0f alpha:a] 11 | @implementation MXSCycleScrollView 12 | 13 | @synthesize scrollView = _scrollView; 14 | @synthesize currentPage = _curPage; 15 | @synthesize datasource = _datasource; 16 | @synthesize delegate = _delegate; 17 | 18 | - (id)initWithFrame:(CGRect)frame 19 | { 20 | self = [super initWithFrame:frame]; 21 | if (self) { 22 | // Initialization code 23 | _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; 24 | _scrollView.delegate = self; 25 | _scrollView.contentSize = CGSizeMake(self.bounds.size.width, (self.bounds.size.height/5)*7); 26 | _scrollView.showsHorizontalScrollIndicator = NO; 27 | _scrollView.showsVerticalScrollIndicator = NO; 28 | _scrollView.contentOffset = CGPointMake(0, (self.bounds.size.height/5)); 29 | 30 | [self addSubview:_scrollView]; 31 | } 32 | return self; 33 | } 34 | //设置初始化页数 35 | - (void)setCurrentSelectPage:(NSInteger)selectPage 36 | { 37 | _curPage = selectPage; 38 | } 39 | 40 | - (void)setDataource:(id)datasource 41 | { 42 | _datasource = datasource; 43 | [self reloadData]; 44 | } 45 | 46 | - (void)reloadData 47 | { 48 | _totalPages = [_datasource numberOfPages:self]; 49 | if (_totalPages == 0) { 50 | return; 51 | } 52 | [self loadData]; 53 | } 54 | 55 | - (void)loadData 56 | { 57 | //从scrollView上移除所有的subview 58 | NSArray *subViews = [_scrollView subviews]; 59 | if([subViews count] != 0) { 60 | [subViews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 61 | } 62 | 63 | [self getDisplayImagesWithCurpage:(int)_curPage]; 64 | 65 | for (int i = 0; i < 7; i++) { 66 | UIView *v = [_curViews objectAtIndex:i]; 67 | v.frame = CGRectOffset(v.frame, 0, v.frame.size.height * i ); 68 | [_scrollView addSubview:v]; 69 | } 70 | 71 | [_scrollView setContentOffset:CGPointMake( 0, (self.bounds.size.height/5) )]; 72 | } 73 | 74 | - (void)getDisplayImagesWithCurpage:(int)page { 75 | int pre1 = [self validPageValue:_curPage-1]; 76 | int pre2 = [self validPageValue:_curPage]; 77 | int pre3 = [self validPageValue:_curPage+1]; 78 | int pre4 = [self validPageValue:_curPage+2]; 79 | int pre5 = [self validPageValue:_curPage+3]; 80 | int pre = [self validPageValue:_curPage+4]; 81 | int last = [self validPageValue:_curPage+5]; 82 | 83 | if (!_curViews) { 84 | _curViews = [[NSMutableArray alloc] init]; 85 | } 86 | 87 | [_curViews removeAllObjects]; 88 | 89 | [_curViews addObject:[_datasource pageAtIndex:pre1 andScrollView:self]]; 90 | [_curViews addObject:[_datasource pageAtIndex:pre2 andScrollView:self]]; 91 | [_curViews addObject:[_datasource pageAtIndex:pre3 andScrollView:self]]; 92 | [_curViews addObject:[_datasource pageAtIndex:pre4 andScrollView:self]]; 93 | [_curViews addObject:[_datasource pageAtIndex:pre5 andScrollView:self]]; 94 | [_curViews addObject:[_datasource pageAtIndex:pre andScrollView:self]]; 95 | [_curViews addObject:[_datasource pageAtIndex:last andScrollView:self]]; 96 | } 97 | 98 | - (int)validPageValue:(NSInteger)value { 99 | 100 | if(value == -1 ) value = _totalPages - 1; 101 | if(value == _totalPages+1) value = 1; 102 | if (value == _totalPages+2) value = 2; 103 | if(value == _totalPages+3) value = 3; 104 | if (value == _totalPages+4) value = 4; 105 | if(value == _totalPages) value = 0; 106 | 107 | 108 | return (int)value; 109 | 110 | } 111 | 112 | - (void)handleTap:(UITapGestureRecognizer *)tap { 113 | 114 | if ([_delegate respondsToSelector:@selector(didClickPage:atIndex:)]) { 115 | [_delegate didClickPage:self atIndex:_curPage]; 116 | } 117 | 118 | } 119 | 120 | - (void)setViewContent:(UIView *)view atIndex:(NSInteger)index 121 | { 122 | if (index == _curPage) { 123 | [_curViews replaceObjectAtIndex:1 withObject:view]; 124 | for (int i = 0; i < 7; i++) { 125 | UIView *v = [_curViews objectAtIndex:i]; 126 | v.userInteractionEnabled = YES; 127 | v.frame = CGRectOffset(v.frame, 0, v.frame.size.height * i); 128 | [_scrollView addSubview:v]; 129 | } 130 | } 131 | } 132 | 133 | - (void)setAfterScrollShowView:(UIScrollView*)scrollview andCurrentPage:(NSInteger)pageNumber 134 | { 135 | UILabel *oneLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber]; 136 | [oneLabel setFont:[UIFont systemFontOfSize:14]]; 137 | [oneLabel setTextColor:RGBA(186.0, 186.0, 186.0, 1.0)]; 138 | UILabel *twoLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+1]; 139 | [twoLabel setFont:[UIFont systemFontOfSize:16]]; 140 | [twoLabel setTextColor:RGBA(113.0, 113.0, 113.0, 1.0)]; 141 | 142 | UILabel *currentLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+2]; 143 | [currentLabel setFont:[UIFont systemFontOfSize:18]]; 144 | [currentLabel setTextColor:[UIColor whiteColor]]; 145 | 146 | UILabel *threeLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+3]; 147 | [threeLabel setFont:[UIFont systemFontOfSize:16]]; 148 | [threeLabel setTextColor:RGBA(113.0, 113.0, 113.0, 1.0)]; 149 | UILabel *fourLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+4]; 150 | [fourLabel setFont:[UIFont systemFontOfSize:14]]; 151 | [fourLabel setTextColor:RGBA(186.0, 186.0, 186.0, 1.0)]; 152 | } 153 | 154 | #pragma mark - UIScrollViewDelegate 155 | - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { 156 | int y = aScrollView.contentOffset.y; 157 | NSInteger page = aScrollView.contentOffset.y/((self.bounds.size.height/5)); 158 | // NSLog(@"第%d页",page); 159 | 160 | if (y>2*(self.bounds.size.height/5)) { 161 | _curPage = [self validPageValue:_curPage+1]; 162 | [self loadData]; 163 | } 164 | if (y<=0) { 165 | _curPage = [self validPageValue:_curPage-1]; 166 | [self loadData]; 167 | } 168 | 169 | if (page>1 || page <=0) { 170 | [self setAfterScrollShowView:aScrollView andCurrentPage:1]; 171 | } 172 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) { 173 | [_delegate scrollviewDidChangeNumber]; 174 | } 175 | } 176 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView 177 | { 178 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 179 | } 180 | 181 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 182 | { 183 | [_scrollView setContentOffset:CGPointMake(0, (self.bounds.size.height/5)) animated:YES]; 184 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 185 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) { 186 | [_delegate scrollviewDidChangeNumber]; 187 | } 188 | } 189 | 190 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView 191 | { 192 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 193 | } 194 | 195 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 196 | [_scrollView setContentOffset:CGPointMake(0, (self.bounds.size.height/5)) animated:YES]; 197 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 198 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) { 199 | [_delegate scrollviewDidChangeNumber]; 200 | } 201 | } 202 | 203 | @end 204 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/JGPicker/JGPicker.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGPicker.m 3 | // JGPicker 4 | // 5 | // Created by stkcctv on 16/12/14. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import "JGPicker.h" 10 | #import "Masonry.h" 11 | 12 | #define ZERO 0 13 | #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width 14 | #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height 15 | #define TOP_HEIGHGT 30 16 | #define BUTTON_WIDTH 30 17 | #define BUTTON_HEIGHT 30 18 | 19 | #define DATAPICKER_HEIGHT 300 20 | 21 | #define WS(weakSelf) __weak __typeof(&*self)weakSelf = self; 22 | 23 | 24 | @implementation JGPicker 25 | 26 | +(instancetype)datePickerViewWithType:(UIDatePickerMode)type andDelegate:(id)delegate; 27 | { 28 | JGPicker *picker = [[JGPicker alloc] initWithFrame:[UIScreen mainScreen].bounds type:type andDelegate:delegate]; 29 | 30 | return picker; 31 | } 32 | 33 | - (instancetype)initWithFrame:(CGRect)frame type:(UIDatePickerMode)type andDelegate:(id)delegate; 34 | { 35 | if (frame.size.width>frame.size.height) 36 | { 37 | float a = frame.size.height; 38 | frame.size.height = frame.size.width; 39 | frame.size.height = a; 40 | } 41 | self = [super initWithFrame:frame]; 42 | if (self) 43 | { 44 | self.type = type; 45 | self.delegate = delegate; 46 | [self addSubview:self.backgroundView]; 47 | [self initializationDatePicker]; 48 | [self initializationTopView]; 49 | [self initializationCancleButton]; 50 | [self initializationDetermineButton]; 51 | } 52 | 53 | 54 | return self; 55 | } 56 | 57 | - (UIView *)backgroundView 58 | { 59 | // 不能用self.backgroundView 不然会循环引用 60 | if (!_backgroundView) 61 | { 62 | self.backgroundView = [[UIView alloc] initWithFrame:self.frame]; 63 | 64 | self.backgroundView.backgroundColor = [UIColor grayColor]; 65 | self.backgroundView.alpha = 0.7; 66 | } 67 | return _backgroundView; 68 | } 69 | 70 | //初始化TopView 71 | - (void)initializationTopView 72 | { 73 | 74 | self.topView = [[UIView alloc] init]; 75 | self.topView.backgroundColor = [UIColor blackColor]; 76 | [self.backgroundView addSubview:self.topView]; 77 | WS(weakSelf); 78 | 79 | [_topView mas_makeConstraints:^(MASConstraintMaker *make) { 80 | make.left.equalTo(weakSelf.backgroundView).with.offset(0); 81 | make.right.equalTo(weakSelf.backgroundView).with.offset(0); 82 | make.bottom.equalTo(_datePicker.mas_top).with.offset(0); 83 | make.height.mas_equalTo(@TOP_HEIGHGT); 84 | }]; 85 | 86 | 87 | } 88 | 89 | 90 | 91 | //初始化datePicker 92 | - (void)initializationDatePicker 93 | { 94 | 95 | self.datePicker = [UIDatePicker new]; 96 | self.datePicker.datePickerMode = self.type; 97 | self.datePicker.backgroundColor = [UIColor whiteColor]; 98 | self.datePicker.minimumDate = [NSDate date]; 99 | [self.datePicker addTarget:self action:@selector(datePickerChange:) forControlEvents:UIControlEventValueChanged]; 100 | [self.backgroundView addSubview:self.datePicker]; 101 | WS(weakSelf); 102 | [_datePicker mas_makeConstraints:^(MASConstraintMaker *make) { 103 | make.left.equalTo(weakSelf.backgroundView).with.offset(ZERO); 104 | make.right.equalTo(weakSelf.backgroundView).with.offset(ZERO); 105 | make.bottom.equalTo(weakSelf.backgroundView).with.offset(ZERO); 106 | make.height.mas_equalTo(@DATAPICKER_HEIGHT); 107 | }]; 108 | 109 | } 110 | 111 | //初始化button 112 | - (void)initializationCancleButton 113 | { 114 | self.cancleButton = [UIButton buttonWithType:UIButtonTypeCustom]; 115 | [self.cancleButton addTarget:self action:@selector(cancleButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 116 | [self.cancleButton setBackgroundImage:[UIImage imageNamed:@"pickerDelete"] forState:UIControlStateNormal]; 117 | [self.topView addSubview:self.cancleButton]; 118 | WS(weakSelf); 119 | [_cancleButton mas_makeConstraints:^(MASConstraintMaker *make) { 120 | make.left.equalTo(weakSelf.topView).with.offset(10); 121 | make.top.equalTo(weakSelf.topView).with.offset(ZERO); 122 | make.bottom.equalTo(weakSelf.topView).with.offset(ZERO); 123 | make.width.mas_equalTo(@BUTTON_WIDTH); 124 | 125 | }]; 126 | } 127 | - (void)initializationDetermineButton 128 | { 129 | self.determineButton = [UIButton buttonWithType:UIButtonTypeCustom]; 130 | [self.determineButton addTarget:self action:@selector(determineButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 131 | [self.determineButton setBackgroundImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal]; 132 | [self.topView addSubview:self.determineButton]; 133 | 134 | [_determineButton mas_makeConstraints:^(MASConstraintMaker *make) { 135 | make.right.equalTo(_topView).with.offset(-10); 136 | make.top.equalTo(_topView).with.offset(ZERO); 137 | make.bottom.equalTo(_topView).with.offset(ZERO); 138 | make.width.mas_equalTo(@BUTTON_WIDTH); 139 | 140 | }]; 141 | } 142 | 143 | - (void)show 144 | { 145 | // [UIView beginAnimations:nil context:nil]; 146 | // [UIView setAnimationCurve:2]; 147 | [[UIApplication sharedApplication].keyWindow addSubview:self]; 148 | // [UIView commitAnimations]; 149 | } 150 | 151 | - (void)end 152 | { 153 | [self removeFromSuperview]; 154 | } 155 | 156 | #pragma mark - DatePicker Method 157 | - (void)datePickerChange:(UIDatePicker *)datePicker 158 | { 159 | // 判断delegate 指向的类是否实现协议方法 160 | if ([self.delegate respondsToSelector:@selector(changeTime:)]) 161 | { 162 | [_delegate changeTime:datePicker.date]; 163 | } 164 | 165 | } 166 | 167 | 168 | 169 | #pragma mark - buttonMethod 170 | 171 | - (void)cancleButtonClick:(UIButton *)sender 172 | { 173 | [self removeFromSuperview]; 174 | } 175 | 176 | - (void)determineButtonClick:(UIButton *)sender 177 | { 178 | if ([_delegate respondsToSelector:@selector(determinSelected:)]) 179 | { 180 | [_delegate determinSelected:self.datePicker.date]; 181 | } 182 | [self end]; 183 | } 184 | 185 | 186 | - (NSDate*)dateFromString:(NSString*)dateString{ 187 | 188 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 189 | switch (self.type) { 190 | case UIDatePickerModeTime: 191 | [dateFormatter setDateFormat:@"HH:mm"]; 192 | break; 193 | case UIDatePickerModeDate: 194 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 195 | break; 196 | case UIDatePickerModeDateAndTime: 197 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; 198 | break; 199 | case UIDatePickerModeCountDownTimer: 200 | [dateFormatter setDateFormat:@"HH:mm"]; 201 | break; 202 | default: 203 | break; 204 | } 205 | NSDate *destDate= [dateFormatter dateFromString:dateString]; 206 | 207 | return destDate; 208 | } 209 | 210 | - (NSString*)stringFromDate:(NSDate*)date{ 211 | 212 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 213 | switch (self.type) { 214 | case UIDatePickerModeTime: 215 | [dateFormatter setDateFormat:@"HH:mm"]; 216 | break; 217 | case UIDatePickerModeDate: 218 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 219 | break; 220 | case UIDatePickerModeDateAndTime: 221 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; 222 | break; 223 | case UIDatePickerModeCountDownTimer: 224 | [dateFormatter setDateFormat:@"HH:mm"]; 225 | break; 226 | default: 227 | break; 228 | } 229 | NSString *destDateString = [dateFormatter stringFromDate:date]; 230 | 231 | return destDateString; 232 | 233 | } 234 | 235 | @end 236 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * Enables Constraints to be created with chainable syntax 13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint) 14 | * or a group of NSLayoutConstraints (MASComposisteConstraint) 15 | */ 16 | @interface MASConstraint : NSObject 17 | 18 | // Chaining Support 19 | 20 | /** 21 | * Modifies the NSLayoutConstraint constant, 22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 24 | */ 25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets; 26 | 27 | /** 28 | * Modifies the NSLayoutConstraint constant, 29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 31 | */ 32 | - (MASConstraint * (^)(CGSize offset))sizeOffset; 33 | 34 | /** 35 | * Modifies the NSLayoutConstraint constant, 36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 38 | */ 39 | - (MASConstraint * (^)(CGPoint offset))centerOffset; 40 | 41 | /** 42 | * Modifies the NSLayoutConstraint constant 43 | */ 44 | - (MASConstraint * (^)(CGFloat offset))offset; 45 | 46 | /** 47 | * Modifies the NSLayoutConstraint constant based on a value type 48 | */ 49 | - (MASConstraint * (^)(NSValue *value))valueOffset; 50 | 51 | /** 52 | * Sets the NSLayoutConstraint multiplier property 53 | */ 54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy; 55 | 56 | /** 57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy 58 | */ 59 | - (MASConstraint * (^)(CGFloat divider))dividedBy; 60 | 61 | /** 62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority 63 | */ 64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority; 65 | 66 | /** 67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow 68 | */ 69 | - (MASConstraint * (^)())priorityLow; 70 | 71 | /** 72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium 73 | */ 74 | - (MASConstraint * (^)())priorityMedium; 75 | 76 | /** 77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh 78 | */ 79 | - (MASConstraint * (^)())priorityHigh; 80 | 81 | /** 82 | * Sets the constraint relation to NSLayoutRelationEqual 83 | * returns a block which accepts one of the following: 84 | * MASViewAttribute, UIView, NSValue, NSArray 85 | * see readme for more details. 86 | */ 87 | - (MASConstraint * (^)(id attr))equalTo; 88 | 89 | /** 90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual 91 | * returns a block which accepts one of the following: 92 | * MASViewAttribute, UIView, NSValue, NSArray 93 | * see readme for more details. 94 | */ 95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo; 96 | 97 | /** 98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual 99 | * returns a block which accepts one of the following: 100 | * MASViewAttribute, UIView, NSValue, NSArray 101 | * see readme for more details. 102 | */ 103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo; 104 | 105 | /** 106 | * Optional semantic property which has no effect but improves the readability of constraint 107 | */ 108 | - (MASConstraint *)with; 109 | 110 | /** 111 | * Optional semantic property which has no effect but improves the readability of constraint 112 | */ 113 | - (MASConstraint *)and; 114 | 115 | /** 116 | * Creates a new MASCompositeConstraint with the called attribute and reciever 117 | */ 118 | - (MASConstraint *)left; 119 | - (MASConstraint *)top; 120 | - (MASConstraint *)right; 121 | - (MASConstraint *)bottom; 122 | - (MASConstraint *)leading; 123 | - (MASConstraint *)trailing; 124 | - (MASConstraint *)width; 125 | - (MASConstraint *)height; 126 | - (MASConstraint *)centerX; 127 | - (MASConstraint *)centerY; 128 | - (MASConstraint *)baseline; 129 | 130 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 131 | 132 | - (MASConstraint *)firstBaseline; 133 | - (MASConstraint *)lastBaseline; 134 | 135 | #endif 136 | 137 | #if TARGET_OS_IPHONE || TARGET_OS_TV 138 | 139 | - (MASConstraint *)leftMargin; 140 | - (MASConstraint *)rightMargin; 141 | - (MASConstraint *)topMargin; 142 | - (MASConstraint *)bottomMargin; 143 | - (MASConstraint *)leadingMargin; 144 | - (MASConstraint *)trailingMargin; 145 | - (MASConstraint *)centerXWithinMargins; 146 | - (MASConstraint *)centerYWithinMargins; 147 | 148 | #endif 149 | 150 | 151 | /** 152 | * Sets the constraint debug name 153 | */ 154 | - (MASConstraint * (^)(id key))key; 155 | 156 | // NSLayoutConstraint constant Setters 157 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks 158 | 159 | /** 160 | * Modifies the NSLayoutConstraint constant, 161 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 162 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 163 | */ 164 | - (void)setInsets:(MASEdgeInsets)insets; 165 | 166 | /** 167 | * Modifies the NSLayoutConstraint constant, 168 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 169 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 170 | */ 171 | - (void)setSizeOffset:(CGSize)sizeOffset; 172 | 173 | /** 174 | * Modifies the NSLayoutConstraint constant, 175 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 176 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 177 | */ 178 | - (void)setCenterOffset:(CGPoint)centerOffset; 179 | 180 | /** 181 | * Modifies the NSLayoutConstraint constant 182 | */ 183 | - (void)setOffset:(CGFloat)offset; 184 | 185 | 186 | // NSLayoutConstraint Installation support 187 | 188 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 189 | /** 190 | * Whether or not to go through the animator proxy when modifying the constraint 191 | */ 192 | @property (nonatomic, copy, readonly) MASConstraint *animator; 193 | #endif 194 | 195 | /** 196 | * Activates an NSLayoutConstraint if it's supported by an OS. 197 | * Invokes install otherwise. 198 | */ 199 | - (void)activate; 200 | 201 | /** 202 | * Deactivates previously installed/activated NSLayoutConstraint. 203 | */ 204 | - (void)deactivate; 205 | 206 | /** 207 | * Creates a NSLayoutConstraint and adds it to the appropriate view. 208 | */ 209 | - (void)install; 210 | 211 | /** 212 | * Removes previously installed NSLayoutConstraint 213 | */ 214 | - (void)uninstall; 215 | 216 | @end 217 | 218 | 219 | /** 220 | * Convenience auto-boxing macros for MASConstraint methods. 221 | * 222 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax. 223 | * A potential drawback of this is that the unprefixed macros will appear in global scope. 224 | */ 225 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__))) 226 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 227 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 228 | 229 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__))) 230 | 231 | 232 | #ifdef MAS_SHORTHAND_GLOBALS 233 | 234 | #define equalTo(...) mas_equalTo(__VA_ARGS__) 235 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__) 236 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__) 237 | 238 | #define offset(...) mas_offset(__VA_ARGS__) 239 | 240 | #endif 241 | 242 | 243 | @interface MASConstraint (AutoboxingSupport) 244 | 245 | /** 246 | * Aliases to corresponding relation methods (for shorthand macros) 247 | * Also needed to aid autocompletion 248 | */ 249 | - (MASConstraint * (^)(id attr))mas_equalTo; 250 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo; 251 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo; 252 | 253 | /** 254 | * A dummy method to aid autocompletion 255 | */ 256 | - (MASConstraint * (^)(id offset))mas_offset; 257 | 258 | @end 259 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/Controllers/JGRootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JGRootViewController.m 3 | // JGDateTime 4 | // 5 | // Created by stkcctv on 16/12/24. 6 | // Copyright © 2016年 JG. All rights reserved. 7 | // 8 | 9 | #import "JGRootViewController.h" 10 | #import "MainViewController.h" 11 | 12 | //尺寸 13 | #define kDeviceHight [UIScreen mainScreen].bounds.size.height 14 | #define kDeviceWidth [UIScreen mainScreen].bounds.size.width 15 | 16 | //颜色定义 17 | #define JGRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] 18 | #define JGGlobaBgColor JGRGBColor(32, 175, 157); 19 | 20 | 21 | //方式一 22 | #import "FDAlertView.h" 23 | #import "RBCustomDatePickerView.h" 24 | 25 | //方式二 26 | #import "JGPicker.h" 27 | 28 | //方式三 29 | #import "GFCalendar.h" 30 | 31 | //方式四 32 | #import "JGPickerView.h" 33 | 34 | 35 | @interface JGRootViewController () { 36 | 37 | UITableViewCell *_index_cell; //标记cell 38 | NSIndexPath *_indexPath; 39 | 40 | } 41 | 42 | @property (nonatomic, strong) UILabel *titleLbl; 43 | @property (nonatomic,strong)JGPicker *picker; 44 | @property (nonatomic,strong)JGPickerView *pickerView; 45 | 46 | @property (nonatomic,strong)NSMutableArray *titleDataArr; 47 | @property (nonatomic,strong)NSMutableArray *detailDataArr; 48 | @end 49 | 50 | static NSString * const JGTableViewCellId = @"JGTableViewCellId"; 51 | 52 | @implementation JGRootViewController 53 | 54 | - (UILabel *)titleLbl { 55 | if (!_titleLbl) { 56 | 57 | _titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, 60)]; 58 | // _titleLbl.backgroundColor = [UIColor lightGrayColor]; 59 | _titleLbl.text = @"时间选择"; 60 | _titleLbl.textColor = [UIColor redColor]; 61 | _titleLbl.font = [UIFont systemFontOfSize:20]; 62 | _titleLbl.textAlignment = NSTextAlignmentCenter; 63 | } 64 | return _titleLbl; 65 | 66 | } 67 | 68 | 69 | 70 | - (NSMutableArray *)titleDataArr { 71 | 72 | if (!_titleDataArr) { 73 | _titleDataArr = [NSMutableArray arrayWithObjects:@"样式一",@"样式二",@"样式三",@"样式四",@"样式五", nil]; 74 | } 75 | return _titleDataArr; 76 | } 77 | 78 | - (NSMutableArray *)detailDataArr { 79 | 80 | if (!_detailDataArr) { 81 | _detailDataArr = [NSMutableArray arrayWithObjects:@"点击选择",@"点击选择",@"点击选择",@"点击选择",@"点击选择", nil]; 82 | } 83 | return _detailDataArr; 84 | } 85 | 86 | 87 | 88 | - (void)viewDidLoad { 89 | [super viewDidLoad]; 90 | 91 | // self.automaticallyAdjustsScrollViewInsets = NO; 92 | 93 | self.view.backgroundColor = [UIColor whiteColor]; 94 | // self.navigationItem.titleView = self.titleLbl; 95 | 96 | 97 | self.tableView.tableHeaderView = self.titleLbl; 98 | // self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0); 99 | 100 | _picker = [[JGPicker alloc] initWithFrame:self.view.frame type:UIDatePickerModeDateAndTime andDelegate:self]; 101 | 102 | 103 | _pickerView = [[JGPickerView alloc] init]; 104 | _pickerView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200); 105 | _pickerView.delegate = self; 106 | // _pickerView.curDate = [NSDate date]; 107 | [self.view addSubview:_pickerView]; 108 | 109 | } 110 | 111 | - (void)didReceiveMemoryWarning { 112 | [super didReceiveMemoryWarning]; 113 | // Dispose of any resources that can be recreated. 114 | } 115 | 116 | #pragma mark - Table view data source 117 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 118 | return self.titleDataArr.count; 119 | } 120 | 121 | 122 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 123 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:JGTableViewCellId]; 124 | 125 | if (cell == nil) { 126 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:JGTableViewCellId]; 127 | } 128 | 129 | cell.textLabel.text = [self.titleDataArr objectAtIndex:indexPath.row]; 130 | cell.detailTextLabel.text = [self.detailDataArr objectAtIndex:indexPath.row]; 131 | // Configure the cell... 132 | 133 | return cell; 134 | } 135 | 136 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 137 | 138 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 139 | 140 | // _index_cell = [tableView cellForRowAtIndexPath:indexPath]; 141 | _indexPath = indexPath; 142 | 143 | if (indexPath.row == 0) { 144 | 145 | FDAlertView *alert = [[FDAlertView alloc] init]; 146 | RBCustomDatePickerView * contentView=[[RBCustomDatePickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)]; 147 | contentView.delegate=self; 148 | alert.contentView = contentView; 149 | [alert show]; 150 | 151 | }else if (indexPath.row == 1) { 152 | 153 | [_picker show]; 154 | }else if (indexPath.row == 2) { 155 | 156 | _pickerView.curDate = [NSDate date]; 157 | [self.pickerView showInView:self.tableView]; 158 | 159 | }else if (indexPath.row == 3) { 160 | 161 | [self loadDateStyle3]; 162 | }else if (indexPath.row == 4) { 163 | 164 | MainViewController *mainVC = [[MainViewController alloc] init]; 165 | [self presentViewController:mainVC animated:YES completion:nil]; 166 | 167 | // [self.navigationController pushViewController:mainVC animated:YES]; 168 | } 169 | 170 | } 171 | 172 | - (void)loadDateStyle3 { 173 | 174 | UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHight)]; 175 | view.backgroundColor = JGGlobaBgColor; 176 | [[UIApplication sharedApplication].keyWindow addSubview:view]; 177 | 178 | CGFloat width = kDeviceWidth - 20.0; 179 | CGPoint origin = CGPointMake(10.0, 64.0 + 70.0); 180 | 181 | GFCalendarView *calendar = [[GFCalendarView alloc] initWithFrameOrigin:origin width:width]; 182 | 183 | // 点击某一天的回调 184 | calendar.didSelectDayHandler = ^(NSInteger year, NSInteger month, NSInteger day) { 185 | 186 | NSString *dateStr = [NSString stringWithFormat:@"%ld-%02ld-%02ld", year, month, day]; 187 | [_detailDataArr replaceObjectAtIndex:_indexPath.row withObject:dateStr]; 188 | 189 | //一个cell刷新 190 | [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_indexPath.row inSection:_indexPath.section]] withRowAnimation:UITableViewRowAnimationNone]; 191 | 192 | [view removeFromSuperview]; 193 | }; 194 | 195 | [view addSubview:calendar]; 196 | } 197 | 198 | 199 | 200 | #pragma mark - 方式一 - 201 | -(void)getTimeToValue:(NSString *)theTimeStr 202 | { 203 | [_detailDataArr replaceObjectAtIndex:_indexPath.row withObject:theTimeStr]; 204 | 205 | //一个cell刷新 206 | [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_indexPath.row inSection:_indexPath.section]] withRowAnimation:UITableViewRowAnimationNone]; 207 | // NSLog(@"我获取到时间了,时间是===%@",theTimeStr); 208 | } 209 | 210 | 211 | #pragma mark - 方式二 - JGPickerDelegate 212 | - (void)changeTime:(NSDate *)date 213 | { 214 | 215 | [_detailDataArr replaceObjectAtIndex:_indexPath.row withObject:[_picker stringFromDate:date]]; 216 | 217 | //一个cell刷新 218 | [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_indexPath.row inSection:_indexPath.section]] withRowAnimation:UITableViewRowAnimationNone]; 219 | 220 | 221 | // NSLog(@"开始时间选择了:%@",[_picker stringFromDate:date]); 222 | } 223 | 224 | - (void)determinSelected:(NSDate *)date 225 | { 226 | 227 | [_detailDataArr replaceObjectAtIndex:_indexPath.row withObject:[_picker stringFromDate:date]]; 228 | 229 | //一个cell刷新 230 | [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_indexPath.row inSection:_indexPath.section]] withRowAnimation:UITableViewRowAnimationNone]; 231 | 232 | // NSLog(@"最终选择了:%@",[_picker stringFromDate:date]); 233 | } 234 | 235 | #pragma mark - 方式四 - JGPickerViewDelegate 236 | -(void)didFinishPickView:(NSString *)date 237 | { 238 | [_detailDataArr replaceObjectAtIndex:_indexPath.row withObject:date]; 239 | 240 | //一个cell刷新 241 | [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_indexPath.row inSection:_indexPath.section]] withRowAnimation:UITableViewRowAnimationNone]; 242 | // NSLog(@"选择了:%@",date); 243 | } 244 | 245 | 246 | 247 | 248 | @end 249 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style1/CycleScollview/MXSCycleScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MXSCycleScrollView.m 3 | // xuexin 4 | // e-mail:rbyyy924805@163.com 5 | // Created by renbing on 3/7/14. 6 | // Copyright (c) 2014 renbing. All rights reserved. 7 | // 8 | 9 | #import "MXSCycleScrollView.h" 10 | #define RGBA(r,g,b,a) [UIColor colorWithRed:(float)r/255.0f green:(float)g/255.0f blue:(float)b/255.0f alpha:a] 11 | @implementation MXSCycleScrollView 12 | 13 | @synthesize scrollView = _scrollView; 14 | @synthesize currentPage = _curPage; 15 | @synthesize datasource = _datasource; 16 | @synthesize delegate = _delegate; 17 | 18 | - (id)initWithFrame:(CGRect)frame 19 | { 20 | self = [super initWithFrame:frame]; 21 | if (self) { 22 | // Initialization code 23 | _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; 24 | _scrollView.delegate = self; 25 | _scrollView.contentSize = CGSizeMake(self.bounds.size.width, (self.bounds.size.height/5)*7); 26 | _scrollView.showsHorizontalScrollIndicator = NO; 27 | _scrollView.showsVerticalScrollIndicator = NO; 28 | _scrollView.contentOffset = CGPointMake(0, (self.bounds.size.height/5)); 29 | 30 | [self addSubview:_scrollView]; 31 | } 32 | return self; 33 | } 34 | //设置初始化页数 35 | - (void)setCurrentSelectPage:(NSInteger)selectPage 36 | { 37 | _curPage = selectPage; 38 | } 39 | 40 | - (void)setDataource:(id)datasource 41 | { 42 | _datasource = datasource; 43 | [self reloadData]; 44 | } 45 | 46 | - (void)reloadData 47 | { 48 | _totalPages = [_datasource numberOfPages:self]; 49 | if (_totalPages == 0) { 50 | return; 51 | } 52 | [self loadData]; 53 | } 54 | 55 | - (void)loadData 56 | { 57 | //从scrollView上移除所有的subview 58 | NSArray *subViews = [_scrollView subviews]; 59 | if([subViews count] != 0) { 60 | [subViews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 61 | } 62 | 63 | [self getDisplayImagesWithCurpage:_curPage]; 64 | 65 | for (int i = 0; i < 7; i++) { 66 | UIView *v = [_curViews objectAtIndex:i]; 67 | // v.userInteractionEnabled = YES; 68 | // UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self 69 | // action:@selector(handleTap:)]; 70 | // [v addGestureRecognizer:singleTap]; 71 | v.frame = CGRectOffset(v.frame, 0, v.frame.size.height * i ); 72 | [_scrollView addSubview:v]; 73 | } 74 | 75 | [_scrollView setContentOffset:CGPointMake( 0, (self.bounds.size.height/5) )]; 76 | } 77 | 78 | - (void)getDisplayImagesWithCurpage:(int)page { 79 | int pre1 = [self validPageValue:_curPage-1]; 80 | int pre2 = [self validPageValue:_curPage]; 81 | int pre3 = [self validPageValue:_curPage+1]; 82 | int pre4 = [self validPageValue:_curPage+2]; 83 | int pre5 = [self validPageValue:_curPage+3]; 84 | int pre = [self validPageValue:_curPage+4]; 85 | int last = [self validPageValue:_curPage+5]; 86 | 87 | if (!_curViews) { 88 | _curViews = [[NSMutableArray alloc] init]; 89 | } 90 | 91 | [_curViews removeAllObjects]; 92 | 93 | [_curViews addObject:[_datasource pageAtIndex:pre1 andScrollView:self]]; 94 | [_curViews addObject:[_datasource pageAtIndex:pre2 andScrollView:self]]; 95 | [_curViews addObject:[_datasource pageAtIndex:pre3 andScrollView:self]]; 96 | [_curViews addObject:[_datasource pageAtIndex:pre4 andScrollView:self]]; 97 | [_curViews addObject:[_datasource pageAtIndex:pre5 andScrollView:self]]; 98 | [_curViews addObject:[_datasource pageAtIndex:pre andScrollView:self]]; 99 | [_curViews addObject:[_datasource pageAtIndex:last andScrollView:self]]; 100 | } 101 | 102 | - (int)validPageValue:(NSInteger)value { 103 | 104 | if(value == -1 ) value = _totalPages - 1; 105 | if(value == _totalPages+1) value = 1; 106 | if (value == _totalPages+2) value = 2; 107 | if(value == _totalPages+3) value = 3; 108 | if (value == _totalPages+4) value = 4; 109 | if(value == _totalPages) value = 0; 110 | 111 | 112 | return value; 113 | 114 | } 115 | 116 | - (void)handleTap:(UITapGestureRecognizer *)tap { 117 | 118 | if ([_delegate respondsToSelector:@selector(didClickPage:atIndex:)]) { 119 | [_delegate didClickPage:self atIndex:_curPage]; 120 | } 121 | 122 | } 123 | 124 | - (void)setViewContent:(UIView *)view atIndex:(NSInteger)index 125 | { 126 | if (index == _curPage) { 127 | [_curViews replaceObjectAtIndex:1 withObject:view]; 128 | for (int i = 0; i < 7; i++) { 129 | UIView *v = [_curViews objectAtIndex:i]; 130 | v.userInteractionEnabled = YES; 131 | // UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self 132 | // action:@selector(handleTap:)]; 133 | // [v addGestureRecognizer:singleTap]; 134 | v.frame = CGRectOffset(v.frame, 0, v.frame.size.height * i); 135 | [_scrollView addSubview:v]; 136 | } 137 | } 138 | } 139 | 140 | - (void)setAfterScrollShowView:(UIScrollView*)scrollview andCurrentPage:(NSInteger)pageNumber 141 | { 142 | UILabel *oneLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber]; 143 | [oneLabel setFont:[UIFont systemFontOfSize:14]]; 144 | [oneLabel setTextColor:RGBA(186.0, 186.0, 186.0, 1.0)]; 145 | UILabel *twoLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+1]; 146 | [twoLabel setFont:[UIFont systemFontOfSize:16]]; 147 | [twoLabel setTextColor:RGBA(113.0, 113.0, 113.0, 1.0)]; 148 | 149 | UILabel *currentLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+2]; 150 | [currentLabel setFont:[UIFont systemFontOfSize:18]]; 151 | [currentLabel setTextColor:[UIColor whiteColor]]; 152 | 153 | UILabel *threeLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+3]; 154 | [threeLabel setFont:[UIFont systemFontOfSize:16]]; 155 | [threeLabel setTextColor:RGBA(113.0, 113.0, 113.0, 1.0)]; 156 | UILabel *fourLabel = (UILabel*)[[scrollview subviews] objectAtIndex:pageNumber+4]; 157 | [fourLabel setFont:[UIFont systemFontOfSize:14]]; 158 | [fourLabel setTextColor:RGBA(186.0, 186.0, 186.0, 1.0)]; 159 | } 160 | 161 | #pragma mark - UIScrollViewDelegate 162 | - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { 163 | int y = aScrollView.contentOffset.y; 164 | NSInteger page = aScrollView.contentOffset.y/((self.bounds.size.height/5)); 165 | // NSLog(@"=========== 第%d页",page); 166 | 167 | if (y>2*(self.bounds.size.height/5)) { 168 | _curPage = [self validPageValue:_curPage+1]; 169 | [self loadData]; 170 | } 171 | if (y<=0) { 172 | _curPage = [self validPageValue:_curPage-1]; 173 | [self loadData]; 174 | } 175 | // //往下翻一张 176 | // if(x >= (4*self.frame.size.width)) { 177 | // _curPage = [self validPageValue:_curPage+1]; 178 | // [self loadData]; 179 | // } 180 | // 181 | // //往上翻 182 | // if(x <= 0) { 183 | // 184 | // } 185 | if (page>1 || page <=0) { 186 | [self setAfterScrollShowView:aScrollView andCurrentPage:1]; 187 | } 188 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) { 189 | [_delegate scrollviewDidChangeNumber]; 190 | } 191 | } 192 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView 193 | { 194 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 195 | } 196 | 197 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 198 | { 199 | [_scrollView setContentOffset:CGPointMake(0, (self.bounds.size.height/5)) animated:YES]; 200 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 201 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) { 202 | [_delegate scrollviewDidChangeNumber]; 203 | } 204 | } 205 | 206 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView 207 | { 208 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 209 | } 210 | 211 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 212 | [_scrollView setContentOffset:CGPointMake(0, (self.bounds.size.height/5)) animated:YES]; 213 | [self setAfterScrollShowView:scrollView andCurrentPage:1]; 214 | if ([_delegate respondsToSelector:@selector(scrollviewDidChangeNumber)]) { 215 | [_delegate scrollviewDidChangeNumber]; 216 | } 217 | } 218 | 219 | @end 220 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style5/NYDateTimeTableViewCell.xib: -------------------------------------------------------------------------------- 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 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 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.m 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 1/20/14. 6 | // 7 | 8 | #import "MASConstraint.h" 9 | #import "MASConstraint+Private.h" 10 | 11 | #define MASMethodNotImplemented() \ 12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \ 13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \ 14 | userInfo:nil] 15 | 16 | @implementation MASConstraint 17 | 18 | #pragma mark - Init 19 | 20 | - (id)init { 21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly."); 22 | return [super init]; 23 | } 24 | 25 | #pragma mark - NSLayoutRelation proxies 26 | 27 | - (MASConstraint * (^)(id))equalTo { 28 | return ^id(id attribute) { 29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 30 | }; 31 | } 32 | 33 | - (MASConstraint * (^)(id))mas_equalTo { 34 | return ^id(id attribute) { 35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 36 | }; 37 | } 38 | 39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo { 40 | return ^id(id attribute) { 41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 42 | }; 43 | } 44 | 45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo { 46 | return ^id(id attribute) { 47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 48 | }; 49 | } 50 | 51 | - (MASConstraint * (^)(id))lessThanOrEqualTo { 52 | return ^id(id attribute) { 53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 54 | }; 55 | } 56 | 57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo { 58 | return ^id(id attribute) { 59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 60 | }; 61 | } 62 | 63 | #pragma mark - MASLayoutPriority proxies 64 | 65 | - (MASConstraint * (^)())priorityLow { 66 | return ^id{ 67 | self.priority(MASLayoutPriorityDefaultLow); 68 | return self; 69 | }; 70 | } 71 | 72 | - (MASConstraint * (^)())priorityMedium { 73 | return ^id{ 74 | self.priority(MASLayoutPriorityDefaultMedium); 75 | return self; 76 | }; 77 | } 78 | 79 | - (MASConstraint * (^)())priorityHigh { 80 | return ^id{ 81 | self.priority(MASLayoutPriorityDefaultHigh); 82 | return self; 83 | }; 84 | } 85 | 86 | #pragma mark - NSLayoutConstraint constant proxies 87 | 88 | - (MASConstraint * (^)(MASEdgeInsets))insets { 89 | return ^id(MASEdgeInsets insets){ 90 | self.insets = insets; 91 | return self; 92 | }; 93 | } 94 | 95 | - (MASConstraint * (^)(CGSize))sizeOffset { 96 | return ^id(CGSize offset) { 97 | self.sizeOffset = offset; 98 | return self; 99 | }; 100 | } 101 | 102 | - (MASConstraint * (^)(CGPoint))centerOffset { 103 | return ^id(CGPoint offset) { 104 | self.centerOffset = offset; 105 | return self; 106 | }; 107 | } 108 | 109 | - (MASConstraint * (^)(CGFloat))offset { 110 | return ^id(CGFloat offset){ 111 | self.offset = offset; 112 | return self; 113 | }; 114 | } 115 | 116 | - (MASConstraint * (^)(NSValue *value))valueOffset { 117 | return ^id(NSValue *offset) { 118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset); 119 | [self setLayoutConstantWithValue:offset]; 120 | return self; 121 | }; 122 | } 123 | 124 | - (MASConstraint * (^)(id offset))mas_offset { 125 | // Will never be called due to macro 126 | return nil; 127 | } 128 | 129 | #pragma mark - NSLayoutConstraint constant setter 130 | 131 | - (void)setLayoutConstantWithValue:(NSValue *)value { 132 | if ([value isKindOfClass:NSNumber.class]) { 133 | self.offset = [(NSNumber *)value doubleValue]; 134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) { 135 | CGPoint point; 136 | [value getValue:&point]; 137 | self.centerOffset = point; 138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) { 139 | CGSize size; 140 | [value getValue:&size]; 141 | self.sizeOffset = size; 142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) { 143 | MASEdgeInsets insets; 144 | [value getValue:&insets]; 145 | self.insets = insets; 146 | } else { 147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value); 148 | } 149 | } 150 | 151 | #pragma mark - Semantic properties 152 | 153 | - (MASConstraint *)with { 154 | return self; 155 | } 156 | 157 | - (MASConstraint *)and { 158 | return self; 159 | } 160 | 161 | #pragma mark - Chaining 162 | 163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute { 164 | MASMethodNotImplemented(); 165 | } 166 | 167 | - (MASConstraint *)left { 168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 169 | } 170 | 171 | - (MASConstraint *)top { 172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 173 | } 174 | 175 | - (MASConstraint *)right { 176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 177 | } 178 | 179 | - (MASConstraint *)bottom { 180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 181 | } 182 | 183 | - (MASConstraint *)leading { 184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 185 | } 186 | 187 | - (MASConstraint *)trailing { 188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 189 | } 190 | 191 | - (MASConstraint *)width { 192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 193 | } 194 | 195 | - (MASConstraint *)height { 196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 197 | } 198 | 199 | - (MASConstraint *)centerX { 200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 201 | } 202 | 203 | - (MASConstraint *)centerY { 204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 205 | } 206 | 207 | - (MASConstraint *)baseline { 208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 209 | } 210 | 211 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 212 | 213 | - (MASConstraint *)firstBaseline { 214 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; 215 | } 216 | - (MASConstraint *)lastBaseline { 217 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; 218 | } 219 | 220 | #endif 221 | 222 | #if TARGET_OS_IPHONE || TARGET_OS_TV 223 | 224 | - (MASConstraint *)leftMargin { 225 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; 226 | } 227 | 228 | - (MASConstraint *)rightMargin { 229 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; 230 | } 231 | 232 | - (MASConstraint *)topMargin { 233 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; 234 | } 235 | 236 | - (MASConstraint *)bottomMargin { 237 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; 238 | } 239 | 240 | - (MASConstraint *)leadingMargin { 241 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; 242 | } 243 | 244 | - (MASConstraint *)trailingMargin { 245 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; 246 | } 247 | 248 | - (MASConstraint *)centerXWithinMargins { 249 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 250 | } 251 | 252 | - (MASConstraint *)centerYWithinMargins { 253 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 254 | } 255 | 256 | #endif 257 | 258 | #pragma mark - Abstract 259 | 260 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); } 261 | 262 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); } 263 | 264 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); } 265 | 266 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); } 267 | 268 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); } 269 | 270 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } 271 | 272 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } 273 | 274 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } 275 | 276 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); } 277 | 278 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 279 | 280 | - (MASConstraint *)animator { MASMethodNotImplemented(); } 281 | 282 | #endif 283 | 284 | - (void)activate { MASMethodNotImplemented(); } 285 | 286 | - (void)deactivate { MASMethodNotImplemented(); } 287 | 288 | - (void)install { MASMethodNotImplemented(); } 289 | 290 | - (void)uninstall { MASMethodNotImplemented(); } 291 | 292 | @end 293 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style5/NYDateTableViewCell.xib: -------------------------------------------------------------------------------- 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 69 | 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 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /自定义时间控件/JGDateTime/JGDateTime/TimeTools/Style2/Masonry/MASConstraintMaker.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraintMaker.h" 10 | #import "MASViewConstraint.h" 11 | #import "MASCompositeConstraint.h" 12 | #import "MASConstraint+Private.h" 13 | #import "MASViewAttribute.h" 14 | #import "View+MASAdditions.h" 15 | 16 | @interface MASConstraintMaker () 17 | 18 | @property (nonatomic, weak) MAS_VIEW *view; 19 | @property (nonatomic, strong) NSMutableArray *constraints; 20 | 21 | @end 22 | 23 | @implementation MASConstraintMaker 24 | 25 | - (id)initWithView:(MAS_VIEW *)view { 26 | self = [super init]; 27 | if (!self) return nil; 28 | 29 | self.view = view; 30 | self.constraints = NSMutableArray.new; 31 | 32 | return self; 33 | } 34 | 35 | - (NSArray *)install { 36 | if (self.removeExisting) { 37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view]; 38 | for (MASConstraint *constraint in installedConstraints) { 39 | [constraint uninstall]; 40 | } 41 | } 42 | NSArray *constraints = self.constraints.copy; 43 | for (MASConstraint *constraint in constraints) { 44 | constraint.updateExisting = self.updateExisting; 45 | [constraint install]; 46 | } 47 | [self.constraints removeAllObjects]; 48 | return constraints; 49 | } 50 | 51 | #pragma mark - MASConstraintDelegate 52 | 53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 54 | NSUInteger index = [self.constraints indexOfObject:constraint]; 55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint]; 57 | } 58 | 59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute]; 61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute]; 62 | if ([constraint isKindOfClass:MASViewConstraint.class]) { 63 | //replace with composite constraint 64 | NSArray *children = @[constraint, newConstraint]; 65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 66 | compositeConstraint.delegate = self; 67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint]; 68 | return compositeConstraint; 69 | } 70 | if (!constraint) { 71 | newConstraint.delegate = self; 72 | [self.constraints addObject:newConstraint]; 73 | } 74 | return newConstraint; 75 | } 76 | 77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs { 78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading 79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX 80 | | MASAttributeCenterY | MASAttributeBaseline 81 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 82 | | MASAttributeFirstBaseline | MASAttributeLastBaseline 83 | #endif 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV 85 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin 86 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins 87 | | MASAttributeCenterYWithinMargins 88 | #endif 89 | ); 90 | 91 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)"); 92 | 93 | NSMutableArray *attributes = [NSMutableArray array]; 94 | 95 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left]; 96 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right]; 97 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top]; 98 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom]; 99 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading]; 100 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing]; 101 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width]; 102 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height]; 103 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX]; 104 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; 105 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; 106 | 107 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 108 | 109 | if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline]; 110 | if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline]; 111 | 112 | #endif 113 | 114 | #if TARGET_OS_IPHONE || TARGET_OS_TV 115 | 116 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin]; 117 | if (attrs & MASAttributeRightMargin) [attributes addObject:self.view.mas_rightMargin]; 118 | if (attrs & MASAttributeTopMargin) [attributes addObject:self.view.mas_topMargin]; 119 | if (attrs & MASAttributeBottomMargin) [attributes addObject:self.view.mas_bottomMargin]; 120 | if (attrs & MASAttributeLeadingMargin) [attributes addObject:self.view.mas_leadingMargin]; 121 | if (attrs & MASAttributeTrailingMargin) [attributes addObject:self.view.mas_trailingMargin]; 122 | if (attrs & MASAttributeCenterXWithinMargins) [attributes addObject:self.view.mas_centerXWithinMargins]; 123 | if (attrs & MASAttributeCenterYWithinMargins) [attributes addObject:self.view.mas_centerYWithinMargins]; 124 | 125 | #endif 126 | 127 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count]; 128 | 129 | for (MASViewAttribute *a in attributes) { 130 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]]; 131 | } 132 | 133 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 134 | constraint.delegate = self; 135 | [self.constraints addObject:constraint]; 136 | return constraint; 137 | } 138 | 139 | #pragma mark - standard Attributes 140 | 141 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 142 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute]; 143 | } 144 | 145 | - (MASConstraint *)left { 146 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 147 | } 148 | 149 | - (MASConstraint *)top { 150 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 151 | } 152 | 153 | - (MASConstraint *)right { 154 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 155 | } 156 | 157 | - (MASConstraint *)bottom { 158 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 159 | } 160 | 161 | - (MASConstraint *)leading { 162 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 163 | } 164 | 165 | - (MASConstraint *)trailing { 166 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 167 | } 168 | 169 | - (MASConstraint *)width { 170 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 171 | } 172 | 173 | - (MASConstraint *)height { 174 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 175 | } 176 | 177 | - (MASConstraint *)centerX { 178 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 179 | } 180 | 181 | - (MASConstraint *)centerY { 182 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 183 | } 184 | 185 | - (MASConstraint *)baseline { 186 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 187 | } 188 | 189 | - (MASConstraint *(^)(MASAttribute))attributes { 190 | return ^(MASAttribute attrs){ 191 | return [self addConstraintWithAttributes:attrs]; 192 | }; 193 | } 194 | 195 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 196 | 197 | - (MASConstraint *)firstBaseline { 198 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; 199 | } 200 | 201 | - (MASConstraint *)lastBaseline { 202 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; 203 | } 204 | 205 | #endif 206 | 207 | 208 | #if TARGET_OS_IPHONE || TARGET_OS_TV 209 | 210 | - (MASConstraint *)leftMargin { 211 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; 212 | } 213 | 214 | - (MASConstraint *)rightMargin { 215 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; 216 | } 217 | 218 | - (MASConstraint *)topMargin { 219 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; 220 | } 221 | 222 | - (MASConstraint *)bottomMargin { 223 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; 224 | } 225 | 226 | - (MASConstraint *)leadingMargin { 227 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; 228 | } 229 | 230 | - (MASConstraint *)trailingMargin { 231 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; 232 | } 233 | 234 | - (MASConstraint *)centerXWithinMargins { 235 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 236 | } 237 | 238 | - (MASConstraint *)centerYWithinMargins { 239 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 240 | } 241 | 242 | #endif 243 | 244 | 245 | #pragma mark - composite Attributes 246 | 247 | - (MASConstraint *)edges { 248 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom]; 249 | } 250 | 251 | - (MASConstraint *)size { 252 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight]; 253 | } 254 | 255 | - (MASConstraint *)center { 256 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY]; 257 | } 258 | 259 | #pragma mark - grouping 260 | 261 | - (MASConstraint *(^)(dispatch_block_t group))group { 262 | return ^id(dispatch_block_t group) { 263 | NSInteger previousCount = self.constraints.count; 264 | group(); 265 | 266 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)]; 267 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 268 | constraint.delegate = self; 269 | return constraint; 270 | }; 271 | } 272 | 273 | @end 274 | --------------------------------------------------------------------------------