Skip to content

Commit fce5381

Browse files
author
Gdxy
committed
init project
1 parent b522cf4 commit fce5381

34 files changed

+3019
-0
lines changed

TLDatePicker.podspec

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Pod::Spec.new do |s|
3+
s.name = 'TLDatePicker'
4+
s.version = '1.0.0'
5+
s.license = 'MIT'
6+
s.ios.deployment_target = '9.0'
7+
s.platform = :ios, '9.0'
8+
s.summary = 'A simple date Picker'
9+
s.homepage = 'https://github.com/LoongerTao/TLDatePicker.git'
10+
s.author = { 'LoongerTao' => '[email protected]' }
11+
s.requires_arc = true
12+
s.source = { :git => 'https://github.com/LoongerTao/TLDatePicker.git', :tag => s.version }
13+
s.source_files = 'TLDatePicker/*.{h,m}'
14+
end
15+
16+
17+
# 错误:xcodebuild: Returned an unsuccessful exit code.
18+
# 一般是有头文件相互依赖,pod检测通不过
19+
20+
21+
# [!] There was an error pushing a new version to trunk: execution expired
22+
# 网络问题,更换网络
23+
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// NSDate+TLCalendarExtention.h
3+
// OusiCanteen
4+
//
5+
// Created by 故乡的云 on 2018/8/20.
6+
// Copyright © 2018年 何青. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface NSDate (TLCalendarExtention)
12+
13+
// MARK: - 比较
14+
/**
15+
* 比较from和self的时间差值 self - from
16+
*/
17+
- (NSDateComponents *)deltaFrom:(NSDate *)from;
18+
/**
19+
* 比较from和self的时间差值,返回秒 self - from
20+
*/
21+
- (NSTimeInterval)compareFrom:(NSDate *)from;
22+
23+
// MARK: - 判断
24+
/**
25+
* 是否为今天
26+
*/
27+
- (BOOL)isToday;
28+
29+
/**
30+
* 是否为同一日期(date=nil时,判断是否为今天)
31+
*/
32+
- (BOOL)isSameDate:(NSDate *)date;;
33+
34+
/**
35+
* 是否与date同一月(date=nil时,判断是否为本月)
36+
*/
37+
- (BOOL)isThisMonth:(NSDate *)date;
38+
39+
/**
40+
* 是否与date同一年(date=nil时,判断是否为今年)
41+
*/
42+
- (BOOL)isThisYear:(NSDate *)date;
43+
44+
/**
45+
* 是否为昨天
46+
*/
47+
- (BOOL)isYesterday;
48+
/**
49+
* 是否为明天
50+
*/
51+
- (BOOL)isTomorrow;
52+
53+
54+
55+
// MARK: - dateFormat(格式化)
56+
/// 世界时间-->本地时间(只是时间偏移,本质还是世界时间)
57+
- (NSDate *)worldDateToLocalDate;
58+
+ (NSDate *)dateWithYear:(NSUInteger)year month:(NSUInteger)month day:(NSUInteger)day;
59+
/// 日期格式化:yyyy-MM-dd HH:mm:ss --> NSDate 世界时间
60+
+ (NSDate *)dateWithFormatString:(NSString *)dateStr;
61+
/// 日期格式化:yyyy-MM-dd HH:mm:ss --> NSDate 本地时间
62+
+ (NSDate *)loaclDateWithFormatString:(NSString *)dateStr;
63+
- (NSString *)dateToFormatString:(NSString *)dateFormat;
64+
65+
66+
67+
// MARK: - 取值
68+
/// 全局默认NSCalendar对象,单粒
69+
@property(nonatomic, strong, readonly) NSCalendar *curCalendar;
70+
71+
/// NSCalendar会转化为本地时间(不能用来转换 - worldDateToLocalDate 格式化的时间,否则会有8小时误差)
72+
@property(nonatomic, assign, readonly) NSInteger year;
73+
/// 本地时间 月
74+
@property(nonatomic, assign, readonly) NSInteger month;
75+
/// 本地时间 日
76+
@property(nonatomic, assign, readonly) NSInteger day;
77+
/// 本地时间 时
78+
@property(nonatomic, assign, readonly) NSInteger hour;
79+
/// 本地时间 分
80+
@property(nonatomic, assign, readonly) NSInteger minute;
81+
/// 本地时间 秒
82+
@property(nonatomic, assign, readonly) NSInteger second;
83+
84+
/// 1: 星期天,2: 星期一...
85+
@property(nonatomic, assign, readonly) NSInteger weekday;
86+
/// 当月第一天的星期
87+
@property(nonatomic, assign, readonly) NSInteger startWeekOfMonth;
88+
/// 当月天数
89+
@property(nonatomic, assign, readonly) NSInteger countOfMonth;
90+
91+
- (NSCalendar *)curCalendar;
92+
- (NSInteger)year;
93+
- (NSInteger)month;
94+
- (NSInteger)weekday;
95+
- (NSInteger)day;
96+
- (NSInteger)hour;
97+
- (NSInteger)minute;
98+
- (NSInteger)second;
99+
- (NSInteger)startWeekOfMonth;
100+
- (NSInteger)countOfMonth;
101+
102+
103+
@end
+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
//
2+
// NSDate+TLCalendarExtention.m
3+
// OusiCanteen
4+
//
5+
// Created by 故乡的云 on 2018/8/20.
6+
// Copyright © 2018年 何青. All rights reserved.
7+
//
8+
9+
#import "NSDate+TLCalendarExtention.h"
10+
11+
@implementation NSDate (TLCalendarExtention)
12+
13+
// MARK: - 比较
14+
- (NSDateComponents *)deltaFrom:(NSDate *)from {
15+
// 日历
16+
NSCalendar *calendar = [NSCalendar currentCalendar];
17+
18+
// 比较时间
19+
NSCalendarUnit unit = NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
20+
21+
return [calendar components:unit fromDate:from toDate:self options:0];
22+
}
23+
24+
- (NSTimeInterval)compareFrom:(NSDate *)from {
25+
NSTimeInterval time = [self timeIntervalSinceDate:from];
26+
27+
return time;
28+
}
29+
30+
// MARK: - 判断
31+
32+
- (BOOL)isToday {
33+
return [[self curCalendar] isDateInToday:self];
34+
}
35+
36+
- (BOOL)isSameDate:(NSDate *)date {
37+
NSCalendar *calendar = [self curCalendar];
38+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
39+
40+
date = date ? date : [NSDate date];
41+
NSDateComponents *nowCmps = [calendar components:unit fromDate:date];
42+
NSDateComponents *selfCmps = [calendar components:unit fromDate:self];
43+
44+
return nowCmps.year == selfCmps.year && nowCmps.month == selfCmps.month && nowCmps.day == selfCmps.day;
45+
}
46+
47+
- (BOOL)isThisMonth:(NSDate *)date;{
48+
NSCalendar *calendar = [self curCalendar];
49+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth;
50+
51+
date = date ? date : [NSDate date];
52+
NSDateComponents *nowCmps = [calendar components:unit fromDate:date];
53+
NSDateComponents *selfCmps = [calendar components:unit fromDate:self];
54+
55+
return nowCmps.year == selfCmps.year && nowCmps.month == selfCmps.month;
56+
}
57+
58+
- (BOOL)isThisYear:(NSDate *)date;{
59+
NSCalendar *calendar = [self curCalendar];
60+
61+
date = date ? date : [NSDate date];
62+
NSInteger nowYear = [calendar component:NSCalendarUnitYear fromDate:date];
63+
NSInteger selfYear = [calendar component:NSCalendarUnitYear fromDate:self];
64+
65+
return nowYear == selfYear;
66+
}
67+
68+
- (BOOL)isYesterday{
69+
return [[self curCalendar] isDateInYesterday:self];
70+
}
71+
72+
- (BOOL)isTomorrow{
73+
return [[self curCalendar] isDateInTomorrow:self];
74+
}
75+
76+
77+
// MARK: - dateFormat(格式化)
78+
+ (NSDate *)dateWithYear:(NSUInteger)year month:(NSUInteger)month day:(NSUInteger)day {
79+
NSString *dateStr = [NSString stringWithFormat:@"%zi-%zi-%zi", year, month, day];
80+
NSDateFormatter *fmt = [NSDateFormatter new];
81+
fmt.dateFormat = @"yyyy-MM-dd";
82+
83+
return [fmt dateFromString:dateStr];
84+
}
85+
86+
+ (NSDate *)dateWithFormatString:(NSString *)dateStr {
87+
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
88+
fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
89+
return [fmt dateFromString:dateStr];
90+
}
91+
92+
+ (NSDate *)loaclDateWithFormatString:(NSString *)dateStr {
93+
return [[NSDate dateWithFormatString:dateStr] worldDateToLocalDate];
94+
}
95+
96+
- (NSString *)dateToFormatString:(NSString *)dateFormat {
97+
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
98+
fmt.dateFormat = dateFormat;
99+
return [fmt stringFromDate:self];
100+
}
101+
102+
// 世界时间转换为本地时间
103+
- (NSDate *)worldDateToLocalDate
104+
{
105+
//获取本地时区(中国时区)
106+
NSTimeZone* localTimeZone = [NSTimeZone localTimeZone];
107+
//计算世界时间与本地时区的时间偏差值
108+
NSInteger offset = [localTimeZone secondsFromGMTForDate:self];
109+
//世界时间+偏差值 得出中国区时间
110+
NSDate *localDate = [self dateByAddingTimeInterval:offset];
111+
112+
return localDate;
113+
}
114+
115+
// MARK: - 取值
116+
static NSCalendar *CALENDAR;
117+
- (NSCalendar *)curCalendar {
118+
if (CALENDAR == nil) {
119+
// 使用静态CALENDAR,防止高频创建影响性能
120+
CALENDAR = [NSCalendar currentCalendar];
121+
}
122+
return CALENDAR;
123+
}
124+
125+
- (NSInteger)year {
126+
NSCalendar *calendar = [self curCalendar];
127+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
128+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
129+
130+
return cmps.year;
131+
}
132+
133+
- (NSInteger)month {
134+
NSCalendar *calendar = [self curCalendar];
135+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
136+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
137+
138+
return cmps.month;
139+
}
140+
141+
- (NSInteger)day {
142+
NSCalendar *calendar = [self curCalendar];
143+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
144+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
145+
146+
return cmps.day;
147+
}
148+
149+
- (NSInteger)hour {
150+
NSCalendar *calendar = [self curCalendar];
151+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
152+
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
153+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
154+
155+
return cmps.hour;
156+
}
157+
158+
- (NSInteger)minute {
159+
NSCalendar *calendar = [self curCalendar];
160+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
161+
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
162+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
163+
164+
return cmps.minute;
165+
}
166+
167+
- (NSInteger)second {
168+
NSCalendar *calendar = [self curCalendar];
169+
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
170+
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
171+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
172+
173+
return cmps.second;
174+
}
175+
176+
- (NSInteger)weekday {
177+
NSCalendar *calendar = [self curCalendar];
178+
NSCalendarUnit unit = NSCalendarUnitWeekday;
179+
NSDateComponents *cmps = [calendar components:unit fromDate:self];
180+
181+
return cmps.weekday;
182+
}
183+
184+
- (NSInteger)startWeekOfMonth {
185+
NSDate *date = [NSDate dateWithYear:self.year month:self.month day:1];
186+
187+
return date.weekday;
188+
}
189+
190+
- (NSInteger)countOfMonth {
191+
NSCalendar *calendar = [self curCalendar];
192+
NSRange range = [calendar rangeOfUnit:NSCalendarUnitDay inUnit: NSCalendarUnitMonth forDate:self];
193+
194+
return range.length;
195+
}
196+
197+
@end
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// TLDPPresentationController.h
3+
// Demo
4+
//
5+
// Created by 故乡的云 on 2019/11/28.
6+
// Copyright © 2019 故乡的云. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface TLDPPresentationController : UIPresentationController
14+
<UIViewControllerTransitioningDelegate>
15+
16+
/// default 圆角 0.f
17+
@property(nonatomic, assign) CGFloat cornerRadius;
18+
/// default 0.2f
19+
@property(nonatomic, assign) NSTimeInterval transitionDuration;
20+
21+
@property(nonatomic, assign) BOOL disableTapMaskToDismiss;
22+
@property(nonatomic, copy) void (^didTapMaskView)(void);
23+
@end
24+
25+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)