123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- //
- // YMGuildManagementDatePickerViewController.m
- // MSYOUPAI
- //
- // Created by 夏军辉 on 2024/5/26.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMGuildManagementDatePickerViewController.h"
- @interface YMGuildManagementDatePickerViewController ()
- @property (nonatomic, strong) UIView *othView;
- @property (nonatomic, strong) UIView *othView1;
- @property (nonatomic, strong) UILabel *startTitleLabel;
- @property (nonatomic, strong) UILabel *endTitleLabel;
- @end
- @implementation YMGuildManagementDatePickerViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- //self.view.backgroundColor = UIColor.clearColor;
-
- [self.view addSubview:self.dismissView];
- [self.view addSubview:self.othView];
- [self.view addSubview:self.contentView];
- [self.view addSubview:self.othView1];
- [self.view addSubview:self.timeSelView];
- [self.timeSelView addSubview:self.startButn];
- [self.timeSelView addSubview:self.endButn];
- [self.timeSelView addSubview:self.startTitleLabel];
- [self.timeSelView addSubview:self.startLabel];
- [self.timeSelView addSubview:self.endTitleLabel];
- [self.timeSelView addSubview:self.endLabel];
-
- [self.view addSubview:self.datePicker];
- [self.view addSubview:self.confirmButn];
-
-
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.view.mas_bottom).offset(0);
- make.leading.trailing.equalTo(self.view);
- make.height.equalTo(adapt(330));
- }];
-
- [self.timeSelView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.leading.trailing.equalTo(self.contentView);
- make.height.mas_equalTo(adapt(66));
- }];
-
- [self.confirmButn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.view.mas_bottom).offset(-self.view.safeAreaInsets.bottom - 10);
- make.centerX.equalTo(self.view);
- make.width.equalTo(adapt(275));
- make.height.equalTo(adapt(54));
- }];
-
- [self.datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.trailing.equalTo(self.contentView);
- make.top.equalTo(self.timeSelView.mas_bottom);
- make.bottom.equalTo(self.confirmButn.mas_top).offset(-10);
- }];
-
- [self.othView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.trailing.equalTo(self.view);
- make.bottom.equalTo(self.contentView);
- make.height.mas_equalTo(adapt(40));
- }];
-
- [self.othView1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.trailing.equalTo(self.view);
- make.bottom.equalTo(self.timeSelView);
- make.height.mas_equalTo(adapt(40));
- }];
- [self.startButn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.leading.bottom.equalTo(self.timeSelView);
- }];
- [self.endButn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.trailing.bottom.equalTo(self.timeSelView);
- make.leading.equalTo(self.startButn.mas_trailing);
- make.width.equalTo(self.startButn);
- }];
- [self.startTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.trailing.equalTo(self.startButn);
- make.top.equalTo(self.startButn).offset(10);
- }];
- [self.startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.leading.trailing.equalTo(self.startButn);
- make.top.equalTo(self.startTitleLabel.mas_bottom);
- make.bottom.equalTo(self.startButn).offset(-10);
- make.height.equalTo(self.startTitleLabel);
- }];
- [self.endTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.endButn).offset(10);
- make.leading.trailing.equalTo(self.endButn);
- }];
- [self.endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.trailing.equalTo(self.endButn);
- make.top.equalTo(self.endTitleLabel.mas_bottom);
- make.bottom.equalTo(self.endButn).offset(-10);
- make.height.equalTo(self.endTitleLabel);
- }];
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
-
- // // 定义你想要的圆角半径
- // CGFloat cornerRadius = 20.0;
- //
- // // 创建一个UIBezierPath对象,只包含左上和右上的圆角
- // UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
- // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.contentView.bounds
- // byRoundingCorners:corners
- // cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
- // // 创建一个CAShapeLayer,并将UIBezierPath设置为它的路径
- // CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- // maskLayer.backgroundColor = UIColor.whiteColor.CGColor;
- // maskLayer.frame = self.contentView.bounds;
- // maskLayer.path = path.CGPath;
- //
- // // 将CAShapeLayer设置为视图的mask
- // self.contentView.layer.mask = maskLayer;
- //
- // {// 定义你想要的圆角半径
- // CGFloat cornerRadius = 20.0;
- //
- // // 创建一个UIBezierPath对象,只包含左上和右上的圆角
- // UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
- // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.timeSelView.bounds
- // byRoundingCorners:corners
- // cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
- // // 创建一个CAShapeLayer,并将UIBezierPath设置为它的路径
- // CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- // maskLayer.backgroundColor = UIColor.whiteColor.CGColor;
- // maskLayer.frame = self.timeSelView.bounds;
- // maskLayer.path = path.CGPath;
- //
- // // 将CAShapeLayer设置为视图的mask
- // self.timeSelView.layer.mask = maskLayer;
- // }
-
- self.contentView.backgroundColor = UIColor.whiteColor;
- self.datePicker.backgroundColor = UIColor.whiteColor;
-
- }
- - (UIView *)dismissView {
- if (!_dismissView) {
- _dismissView = [[UIView alloc] initWithFrame:self.view.bounds];
- _dismissView.backgroundColor = HexColorFromRGBA(0x000000, 0.6);
- [_dismissView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissViewClick)]];
- }
- return _dismissView;
- }
- - (UIView *)contentView {
- if (!_contentView) {
- _contentView = [[UIView alloc] init];
- _contentView.backgroundColor = UIColor.whiteColor;
- _contentView.layer.cornerRadius = 20;
- _contentView.layer.masksToBounds = YES;
- }
- return _contentView;
- }
- - (UIView *)timeSelView {
- if (!_timeSelView) {
- _timeSelView = [[UIView alloc] init];
- _timeSelView.backgroundColor = HexColorFromRGBA(0xF5F5F7, 1);
- _timeSelView.layer.cornerRadius = 20;
- _timeSelView.layer.masksToBounds = YES;
- }
- return _timeSelView;
- }
- - (UIView *)othView {
- if (!_othView) {
- _othView = [[UIView alloc] init];
- _othView.backgroundColor = UIColor.whiteColor;
- }
- return _othView;
- }
- - (UIView *)othView1 {
- if (!_othView1) {
- _othView1 = [[UIView alloc] init];
- _othView1.backgroundColor = HexColorFromRGBA(0xF5F5F7, 1);
- }
- return _othView1;
- }
- - (UIButton *)startButn {
- if (!_startButn) {
- _startButn = [UIButton buttonWithType:UIButtonTypeCustom];
- _startButn.backgroundColor = [UIColor clearColor];
- [_startButn addTarget:self action:@selector(startButnClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _startButn;
- }
- - (UIButton *)endButn {
- if (!_endButn) {
- _endButn = [UIButton buttonWithType:UIButtonTypeCustom];
- _endButn.backgroundColor = [UIColor clearColor];
- [_endButn addTarget:self action:@selector(endButnClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _endButn;
- }
- - (UIDatePicker *)datePicker {
- if (!_datePicker) {
- UIDatePicker *datePicker = [[UIDatePicker alloc]init];
- datePicker.backgroundColor = [UIColor whiteColor];
- if (@available(iOS 13.4, *)) {
- datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
- }
- datePicker.datePickerMode = UIDatePickerModeDate;
- // 添加目标-动作,当值改变时触发
- [_datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
- _datePicker.minimumDate = [[NSDate date] dateByAddingTimeInterval:-60 * 24 * 60 * 60];
- _datePicker.maximumDate = [NSDate date];
- _datePicker = datePicker;
- }
- return _datePicker;
- }
- - (UIButton *)confirmButn {
- if (!_confirmButn) {
- _confirmButn = [UIButton buttonWithType:UIButtonTypeCustom];
- _confirmButn.backgroundColor = HexColorFromRGBA(0xFF76C0, 1);
- _confirmButn.layer.cornerRadius = 16;
- _confirmButn.layer.masksToBounds = YES;
- [_confirmButn setTitle:@"确定" forState:(UIControlStateNormal)];
- }
- return _confirmButn;
- }
- - (UILabel *)startTitleLabel {
- if (!_startTitleLabel) {
- _startTitleLabel = [[UILabel alloc] init];
- _startTitleLabel.text = @"开始时间";
- _startTitleLabel.font = LCFont(15);
- _startTitleLabel.textColor = UIColor.blackColor;
- _startTitleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _startTitleLabel;
- }
- - (UILabel *)startLabel {
- if (!_startLabel) {
- _startLabel = [[UILabel alloc] init];
- _startLabel.text = @"开始时间";
- _startLabel.font = LCFont(12);
- _startLabel.textColor = UIColor.blackColor;
- _startLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _startLabel;
- }
- - (UILabel *)endTitleLabel {
- if (!_endTitleLabel) {
- _endTitleLabel = [[UILabel alloc] init];
- _endTitleLabel.text = @"结束时间";
- _endTitleLabel.font = LCFont(15);
- _endTitleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
- _endTitleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _endTitleLabel;
- }
- - (UILabel *)endLabel {
- if (!_endLabel) {
- _endLabel = [[UILabel alloc] init];
- _endLabel.text = @"结束时间";
- _endLabel.font = LCFont(12);
- _endLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
- _endLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _endLabel;
- }
- - (void)setStartTime:(NSString *)startTime; {
- self.startLabel.text = startTime;
- }
- - (void)setEndTime:(NSString *)endTime; {
- self.endLabel.text = endTime;
- }
- - (void)startButnClick:(UIButton *)sender {
- self.startTitleLabel.textColor = UIColor.blackColor;
- self.startLabel.textColor = UIColor.blackColor;
-
- self.endTitleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
- self.endLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
- self.isStart = YES;
- self.isEnd = NO;
- }
- - (void)endButnClick:(UIButton *)sender {
- self.endTitleLabel.textColor = UIColor.blackColor;
- self.endLabel.textColor = UIColor.blackColor;
-
- self.startTitleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
- self.startLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.45];
- self.isStart = NO;
- self.isEnd = YES;
- }
- - (void)dismissViewClick {
- [self dismissViewControllerAnimated:false completion:^{
-
- }];
- }
- - (void)datePickerValueChanged:(UIDatePicker *)picker {
- [self updateSelectedDateLabel];
- }
- - (void)updateSelectedDateLabel {
- // 获取选择的日期
- NSDate *selectedDate = self.datePicker.date;
-
- // 格式化日期
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- dateFormatter.dateStyle = NSDateFormatterMediumStyle;
- dateFormatter.timeStyle = NSDateFormatterNoStyle;
-
- // 设置标签文本为格式化后的日期字符串
- //self.selectedDateLabel.text = [dateFormatter stringFromDate:selectedDate];
- }
- @end
|