YMGuildManagementDatePickerViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. //
  2. // YMGuildManagementDatePickerViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by 夏军辉 on 2024/5/26.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMGuildManagementDatePickerViewController.h"
  9. @interface YMGuildManagementDatePickerViewController ()
  10. @property (nonatomic, strong) UIView *othView;
  11. @property (nonatomic, strong) UIView *othView1;
  12. @property (nonatomic, strong) UILabel *startTitleLabel;
  13. @property (nonatomic, strong) UILabel *endTitleLabel;
  14. @end
  15. @implementation YMGuildManagementDatePickerViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. //self.view.backgroundColor = UIColor.clearColor;
  19. [self.view addSubview:self.dismissView];
  20. [self.view addSubview:self.othView];
  21. [self.view addSubview:self.contentView];
  22. [self.view addSubview:self.othView1];
  23. [self.view addSubview:self.timeSelView];
  24. [self.timeSelView addSubview:self.startButn];
  25. [self.timeSelView addSubview:self.endButn];
  26. [self.timeSelView addSubview:self.startTitleLabel];
  27. [self.timeSelView addSubview:self.startLabel];
  28. [self.timeSelView addSubview:self.endTitleLabel];
  29. [self.timeSelView addSubview:self.endLabel];
  30. [self.view addSubview:self.datePicker];
  31. [self.view addSubview:self.confirmButn];
  32. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.bottom.equalTo(self.view.mas_bottom).offset(0);
  34. make.leading.trailing.equalTo(self.view);
  35. make.height.equalTo(adapt(330));
  36. }];
  37. [self.timeSelView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.contentView);
  39. make.leading.trailing.equalTo(self.contentView);
  40. make.height.mas_equalTo(adapt(66));
  41. }];
  42. [self.confirmButn mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.bottom.equalTo(self.view.mas_bottom).offset(-self.view.safeAreaInsets.bottom - 10);
  44. make.centerX.equalTo(self.view);
  45. make.width.equalTo(adapt(275));
  46. make.height.equalTo(adapt(54));
  47. }];
  48. [self.datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.leading.trailing.equalTo(self.contentView);
  50. make.top.equalTo(self.timeSelView.mas_bottom);
  51. make.bottom.equalTo(self.confirmButn.mas_top).offset(-10);
  52. }];
  53. [self.othView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.leading.trailing.equalTo(self.view);
  55. make.bottom.equalTo(self.contentView);
  56. make.height.mas_equalTo(adapt(40));
  57. }];
  58. [self.othView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.leading.trailing.equalTo(self.view);
  60. make.bottom.equalTo(self.timeSelView);
  61. make.height.mas_equalTo(adapt(40));
  62. }];
  63. [self.startButn mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.leading.bottom.equalTo(self.timeSelView);
  65. }];
  66. [self.endButn mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.top.trailing.bottom.equalTo(self.timeSelView);
  68. make.leading.equalTo(self.startButn.mas_trailing);
  69. make.width.equalTo(self.startButn);
  70. }];
  71. [self.startTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.leading.trailing.equalTo(self.startButn);
  73. make.top.equalTo(self.startButn).offset(10);
  74. }];
  75. [self.startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.bottom.leading.trailing.equalTo(self.startButn);
  77. make.top.equalTo(self.startTitleLabel.mas_bottom);
  78. make.bottom.equalTo(self.startButn).offset(-10);
  79. make.height.equalTo(self.startTitleLabel);
  80. }];
  81. [self.endTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(self.endButn).offset(10);
  83. make.leading.trailing.equalTo(self.endButn);
  84. }];
  85. [self.endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.leading.trailing.equalTo(self.endButn);
  87. make.top.equalTo(self.endTitleLabel.mas_bottom);
  88. make.bottom.equalTo(self.endButn).offset(-10);
  89. make.height.equalTo(self.endTitleLabel);
  90. }];
  91. }
  92. - (void)viewWillAppear:(BOOL)animated {
  93. [super viewWillAppear:animated];
  94. // // 定义你想要的圆角半径
  95. // CGFloat cornerRadius = 20.0;
  96. //
  97. // // 创建一个UIBezierPath对象,只包含左上和右上的圆角
  98. // UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
  99. // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.contentView.bounds
  100. // byRoundingCorners:corners
  101. // cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
  102. // // 创建一个CAShapeLayer,并将UIBezierPath设置为它的路径
  103. // CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  104. // maskLayer.backgroundColor = UIColor.whiteColor.CGColor;
  105. // maskLayer.frame = self.contentView.bounds;
  106. // maskLayer.path = path.CGPath;
  107. //
  108. // // 将CAShapeLayer设置为视图的mask
  109. // self.contentView.layer.mask = maskLayer;
  110. //
  111. // {// 定义你想要的圆角半径
  112. // CGFloat cornerRadius = 20.0;
  113. //
  114. // // 创建一个UIBezierPath对象,只包含左上和右上的圆角
  115. // UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
  116. // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.timeSelView.bounds
  117. // byRoundingCorners:corners
  118. // cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
  119. // // 创建一个CAShapeLayer,并将UIBezierPath设置为它的路径
  120. // CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  121. // maskLayer.backgroundColor = UIColor.whiteColor.CGColor;
  122. // maskLayer.frame = self.timeSelView.bounds;
  123. // maskLayer.path = path.CGPath;
  124. //
  125. // // 将CAShapeLayer设置为视图的mask
  126. // self.timeSelView.layer.mask = maskLayer;
  127. // }
  128. self.contentView.backgroundColor = UIColor.whiteColor;
  129. self.datePicker.backgroundColor = UIColor.whiteColor;
  130. }
  131. - (UIView *)dismissView {
  132. if (!_dismissView) {
  133. _dismissView = [[UIView alloc] initWithFrame:self.view.bounds];
  134. _dismissView.backgroundColor = HexColorFromRGBA(0x000000, 0.6);
  135. [_dismissView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissViewClick)]];
  136. }
  137. return _dismissView;
  138. }
  139. - (UIView *)contentView {
  140. if (!_contentView) {
  141. _contentView = [[UIView alloc] init];
  142. _contentView.backgroundColor = UIColor.whiteColor;
  143. _contentView.layer.cornerRadius = 20;
  144. _contentView.layer.masksToBounds = YES;
  145. }
  146. return _contentView;
  147. }
  148. - (UIView *)timeSelView {
  149. if (!_timeSelView) {
  150. _timeSelView = [[UIView alloc] init];
  151. _timeSelView.backgroundColor = HexColorFromRGBA(0xF5F5F7, 1);
  152. _timeSelView.layer.cornerRadius = 20;
  153. _timeSelView.layer.masksToBounds = YES;
  154. }
  155. return _timeSelView;
  156. }
  157. - (UIView *)othView {
  158. if (!_othView) {
  159. _othView = [[UIView alloc] init];
  160. _othView.backgroundColor = UIColor.whiteColor;
  161. }
  162. return _othView;
  163. }
  164. - (UIView *)othView1 {
  165. if (!_othView1) {
  166. _othView1 = [[UIView alloc] init];
  167. _othView1.backgroundColor = HexColorFromRGBA(0xF5F5F7, 1);
  168. }
  169. return _othView1;
  170. }
  171. - (UIButton *)startButn {
  172. if (!_startButn) {
  173. _startButn = [UIButton buttonWithType:UIButtonTypeCustom];
  174. _startButn.backgroundColor = [UIColor clearColor];
  175. [_startButn addTarget:self action:@selector(startButnClick:) forControlEvents:UIControlEventTouchUpInside];
  176. }
  177. return _startButn;
  178. }
  179. - (UIButton *)endButn {
  180. if (!_endButn) {
  181. _endButn = [UIButton buttonWithType:UIButtonTypeCustom];
  182. _endButn.backgroundColor = [UIColor clearColor];
  183. [_endButn addTarget:self action:@selector(endButnClick:) forControlEvents:UIControlEventTouchUpInside];
  184. }
  185. return _endButn;
  186. }
  187. - (UIDatePicker *)datePicker {
  188. if (!_datePicker) {
  189. UIDatePicker *datePicker = [[UIDatePicker alloc]init];
  190. datePicker.backgroundColor = [UIColor whiteColor];
  191. if (@available(iOS 13.4, *)) {
  192. datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
  193. }
  194. datePicker.datePickerMode = UIDatePickerModeDate;
  195. // 添加目标-动作,当值改变时触发
  196. [_datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
  197. _datePicker.minimumDate = [[NSDate date] dateByAddingTimeInterval:-60 * 24 * 60 * 60];
  198. _datePicker.maximumDate = [NSDate date];
  199. _datePicker = datePicker;
  200. }
  201. return _datePicker;
  202. }
  203. - (UIButton *)confirmButn {
  204. if (!_confirmButn) {
  205. _confirmButn = [UIButton buttonWithType:UIButtonTypeCustom];
  206. _confirmButn.backgroundColor = HexColorFromRGBA(0xFF76C0, 1);
  207. _confirmButn.layer.cornerRadius = 16;
  208. _confirmButn.layer.masksToBounds = YES;
  209. [_confirmButn setTitle:@"确定" forState:(UIControlStateNormal)];
  210. }
  211. return _confirmButn;
  212. }
  213. - (UILabel *)startTitleLabel {
  214. if (!_startTitleLabel) {
  215. _startTitleLabel = [[UILabel alloc] init];
  216. _startTitleLabel.text = @"开始时间";
  217. _startTitleLabel.font = LCFont(15);
  218. _startTitleLabel.textColor = UIColor.blackColor;
  219. _startTitleLabel.textAlignment = NSTextAlignmentCenter;
  220. }
  221. return _startTitleLabel;
  222. }
  223. - (UILabel *)startLabel {
  224. if (!_startLabel) {
  225. _startLabel = [[UILabel alloc] init];
  226. _startLabel.text = @"开始时间";
  227. _startLabel.font = LCFont(12);
  228. _startLabel.textColor = UIColor.blackColor;
  229. _startLabel.textAlignment = NSTextAlignmentCenter;
  230. }
  231. return _startLabel;
  232. }
  233. - (UILabel *)endTitleLabel {
  234. if (!_endTitleLabel) {
  235. _endTitleLabel = [[UILabel alloc] init];
  236. _endTitleLabel.text = @"结束时间";
  237. _endTitleLabel.font = LCFont(15);
  238. _endTitleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
  239. _endTitleLabel.textAlignment = NSTextAlignmentCenter;
  240. }
  241. return _endTitleLabel;
  242. }
  243. - (UILabel *)endLabel {
  244. if (!_endLabel) {
  245. _endLabel = [[UILabel alloc] init];
  246. _endLabel.text = @"结束时间";
  247. _endLabel.font = LCFont(12);
  248. _endLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
  249. _endLabel.textAlignment = NSTextAlignmentCenter;
  250. }
  251. return _endLabel;
  252. }
  253. - (void)setStartTime:(NSString *)startTime; {
  254. self.startLabel.text = startTime;
  255. }
  256. - (void)setEndTime:(NSString *)endTime; {
  257. self.endLabel.text = endTime;
  258. }
  259. - (void)startButnClick:(UIButton *)sender {
  260. self.startTitleLabel.textColor = UIColor.blackColor;
  261. self.startLabel.textColor = UIColor.blackColor;
  262. self.endTitleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
  263. self.endLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
  264. self.isStart = YES;
  265. self.isEnd = NO;
  266. }
  267. - (void)endButnClick:(UIButton *)sender {
  268. self.endTitleLabel.textColor = UIColor.blackColor;
  269. self.endLabel.textColor = UIColor.blackColor;
  270. self.startTitleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
  271. self.startLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
  272. self.isStart = NO;
  273. self.isEnd = YES;
  274. }
  275. - (void)dismissViewClick {
  276. [self dismissViewControllerAnimated:false completion:^{
  277. }];
  278. }
  279. - (void)datePickerValueChanged:(UIDatePicker *)picker {
  280. [self updateSelectedDateLabel];
  281. }
  282. - (void)updateSelectedDateLabel {
  283. // 获取选择的日期
  284. NSDate *selectedDate = self.datePicker.date;
  285. // 格式化日期
  286. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  287. dateFormatter.dateStyle = NSDateFormatterMediumStyle;
  288. dateFormatter.timeStyle = NSDateFormatterNoStyle;
  289. // 设置标签文本为格式化后的日期字符串
  290. //self.selectedDateLabel.text = [dateFormatter stringFromDate:selectedDate];
  291. }
  292. @end