CCDatePickerView.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // CCDatePickerView.h
  3. // ChooseTimePickerView
  4. //
  5. // Created by 陈红 on 2017/3/12.
  6. // Copyright © 2017年 陈红:ch_email@126.cm. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #define D_MINUTE 60
  10. #define D_HOUR 3600
  11. #define D_DAY 86400
  12. #define D_WEEK 604800
  13. #define D_YEAR 31556926
  14. typedef void(^dateBlock)(NSDate *dateString);
  15. @interface CCDatePickerView : UIView<UIPickerViewDelegate,UIPickerViewDataSource>
  16. @property (nonatomic,strong)UIPickerView *datePicker;
  17. /**
  18. 时间选择按钮
  19. */
  20. @property(nonatomic,strong)UIButton *cancelButton;
  21. @property(nonatomic,strong)UIButton *okButton;
  22. /**
  23. NSDate回调
  24. */
  25. @property (nonatomic,copy)dateBlock blcok;
  26. /**
  27. 时间的标题
  28. */
  29. @property(nonatomic,strong)UILabel *chooseTimeLabel;
  30. /**
  31. 控件出现
  32. */
  33. - (void)fadeIn;
  34. /**
  35. 控件显示
  36. */
  37. - (void)fadeOut;
  38. @end
  39. @interface NSDate (Extension)
  40. + (NSCalendar *) currentCalendar; // avoid bottlenecks
  41. // Relative dates from the current date
  42. + (NSDate *) dateTomorrow;
  43. + (NSDate *) dateYesterday;
  44. + (NSDate *) dateWithDaysFromNow: (NSInteger) days;
  45. + (NSDate *) dateWithDaysBeforeNow: (NSInteger) days;
  46. + (NSDate *) dateWithHoursFromNow: (NSInteger) dHours;
  47. + (NSDate *) dateWithHoursBeforeNow: (NSInteger) dHours;
  48. + (NSDate *) dateWithMinutesFromNow: (NSInteger) dMinutes;
  49. + (NSDate *) dateWithMinutesBeforeNow: (NSInteger) dMinutes;
  50. + (NSDate *)date:(NSString *)datestr WithFormat:(NSString *)format;
  51. // Short string utilities
  52. - (NSString *) stringWithDateStyle: (NSDateFormatterStyle) dateStyle timeStyle: (NSDateFormatterStyle) timeStyle;
  53. - (NSString *) stringWithFormat: (NSString *) format;
  54. @property (nonatomic, readonly) NSString *shortString;
  55. @property (nonatomic, readonly) NSString *shortDateString;
  56. @property (nonatomic, readonly) NSString *shortTimeString;
  57. @property (nonatomic, readonly) NSString *mediumString;
  58. @property (nonatomic, readonly) NSString *mediumDateString;
  59. @property (nonatomic, readonly) NSString *mediumTimeString;
  60. @property (nonatomic, readonly) NSString *longString;
  61. @property (nonatomic, readonly) NSString *longDateString;
  62. @property (nonatomic, readonly) NSString *longTimeString;
  63. // Comparing dates
  64. - (BOOL) isEqualToDateIgnoringTime: (NSDate *) aDate;
  65. - (BOOL) isToday;
  66. - (BOOL) isTomorrow;
  67. - (BOOL) isYesterday;
  68. - (BOOL) isSameWeekAsDate: (NSDate *) aDate;
  69. - (BOOL) isThisWeek;
  70. - (BOOL) isNextWeek;
  71. - (BOOL) isLastWeek;
  72. - (BOOL) isSameMonthAsDate: (NSDate *) aDate;
  73. - (BOOL) isThisMonth;
  74. - (BOOL) isNextMonth;
  75. - (BOOL) isLastMonth;
  76. - (BOOL) isSameYearAsDate: (NSDate *) aDate;
  77. - (BOOL) isThisYear;
  78. - (BOOL) isNextYear;
  79. - (BOOL) isLastYear;
  80. - (BOOL) isEarlierThanDate: (NSDate *) aDate;
  81. - (BOOL) isLaterThanDate: (NSDate *) aDate;
  82. - (BOOL) isInFuture;
  83. - (BOOL) isInPast;
  84. // Date roles
  85. - (BOOL) isTypicallyWorkday;
  86. - (BOOL) isTypicallyWeekend;
  87. // Adjusting dates
  88. - (NSDate *) dateByAddingYears: (NSInteger) dYears;
  89. - (NSDate *) dateBySubtractingYears: (NSInteger) dYears;
  90. - (NSDate *) dateByAddingMonths: (NSInteger) dMonths;
  91. - (NSDate *) dateBySubtractingMonths: (NSInteger) dMonths;
  92. - (NSDate *) dateByAddingDays: (NSInteger) dDays;
  93. - (NSDate *) dateBySubtractingDays: (NSInteger) dDays;
  94. - (NSDate *) dateByAddingHours: (NSInteger) dHours;
  95. - (NSDate *) dateBySubtractingHours: (NSInteger) dHours;
  96. - (NSDate *) dateByAddingMinutes: (NSInteger) dMinutes;
  97. - (NSDate *) dateBySubtractingMinutes: (NSInteger) dMinutes;
  98. // Date extremes
  99. - (NSDate *) dateAtStartOfDay;
  100. - (NSDate *) dateAtEndOfDay;
  101. // Retrieving intervals
  102. - (NSInteger) minutesAfterDate: (NSDate *) aDate;
  103. - (NSInteger) minutesBeforeDate: (NSDate *) aDate;
  104. - (NSInteger) hoursAfterDate: (NSDate *) aDate;
  105. - (NSInteger) hoursBeforeDate: (NSDate *) aDate;
  106. - (NSInteger) daysAfterDate: (NSDate *) aDate;
  107. - (NSInteger) daysBeforeDate: (NSDate *) aDate;
  108. - (NSInteger)distanceInDaysToDate:(NSDate *)anotherDate;
  109. // Decomposing dates
  110. @property (readonly) NSInteger nearestHour;
  111. @property (readonly) NSInteger hour;
  112. @property (readonly) NSInteger minute;
  113. @property (readonly) NSInteger seconds;
  114. @property (readonly) NSInteger day;
  115. @property (readonly) NSInteger month;
  116. @property (readonly) NSInteger week;
  117. @property (readonly) NSInteger weekday;
  118. @property (readonly) NSInteger nthWeekday; // e.g. 2nd Tuesday of the month == 2
  119. @property (readonly) NSInteger year;
  120. - (NSDate *)dateWithYMD;
  121. - (NSDate *)dateWithFormatter:(NSString *)formatter;
  122. @end
  123. @interface UIView (Extension)
  124. /** 起点x坐标 */
  125. @property (nonatomic, assign) CGFloat x;
  126. /** 起点y坐标 */
  127. @property (nonatomic, assign) CGFloat y;
  128. /** 中心点x坐标 */
  129. @property (nonatomic, assign) CGFloat centerX;
  130. /** 中心点y坐标 */
  131. @property (nonatomic, assign) CGFloat centerY;
  132. /** 宽度 */
  133. @property (nonatomic, assign) CGFloat width;
  134. /** 高度 */
  135. @property (nonatomic, assign) CGFloat height;
  136. /** 顶部 */
  137. @property (nonatomic, assign) CGFloat top;
  138. /** 底部 */
  139. @property (nonatomic, assign) CGFloat bottom;
  140. /** 左边 */
  141. @property (nonatomic, assign) CGFloat left;
  142. /** 右边 */
  143. @property (nonatomic, assign) CGFloat right;
  144. /** size */
  145. @property (nonatomic, assign) CGSize size;
  146. /** origin */
  147. @property (nonatomic, assign) CGPoint origin;
  148. /** 设置圆角 */
  149. - (void)rounded:(CGFloat)cornerRadius;
  150. /** 设置圆角和边框 */
  151. - (void)rounded:(CGFloat)cornerRadius width:(CGFloat)borderWidth color:(UIColor *)borderColor;
  152. /** 设置边框 */
  153. - (void)border:(CGFloat)borderWidth color:(UIColor *)borderColor;
  154. /** 给哪几个角设置圆角 */
  155. -(void)round:(CGFloat)cornerRadius RectCorners:(UIRectCorner)rectCorner;
  156. /** 设置阴影 */
  157. -(void)shadow:(UIColor *)shadowColor opacity:(CGFloat)opacity radius:(CGFloat)radius offset:(CGSize)offset;
  158. - (UIViewController *)viewController;
  159. + (CGFloat)getLabelHeightByWidth:(CGFloat)width Title:(NSString *)title font:(UIFont *)font;
  160. @end