You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

181 lines
8.8 KiB

//
// AddTimeframeViewController.m
// tongxin
//
// Created by ecell on 2023/7/12.
// Copyright © 2023 xTT. All rights reserved.
//
#import "AddTimeframeViewController.h"
#import <BRDatePickerView.h>
@interface AddTimeframeViewController ()
@property (nonatomic ,weak) UIButton *startTimeBtn;
@property (nonatomic ,weak) UIButton *endTimeBtn;
@property (nonatomic ,strong) NSMutableArray *btnArr;
@end
@implementation AddTimeframeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.zx_navTitle = @"添加使用时段";
self.view.backgroundColor = tabViewBG;
WEAKSELF
[self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
weakSelf.blockAddClick(F(@"%@-%@-%@", weakSelf.startTimeBtn.currentTitle,weakSelf.endTimeBtn.currentTitle,[self.btnArr componentsJoinedByString:@""]));
[weakSelf.navigationController popViewControllerAnimated:YES];
}];
NSArray *arr = @[@"时间",@"星期"];
NSArray *timeArr = @[@"",@"",@"",@"",@"",@"",@""];
UIView *bgView = [UICommon ui_view:CGRectMake(0, iPhoneX_NavHeight, ScreenWidth, Adapted(55)*arr.count) backgroundColor:KKWhiteColorColor cornerRadius:0 borderWidth:0 borderColor:KKWhiteColorColor];
[self.view addSubview:bgView];
for (int i = 0; i < arr.count; i++)
{
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(14) textColor:KKTextColor text:arr[i] Radius:0];
[bgView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(15);
make.top.equalTo(bgView).offset(i*Adapted(55));
make.height.mas_equalTo(Adapted(55));
}];
if (i < arr.count)
{
UIImageView *line = [UIImageView new];
line.backgroundColor = RGB(235, 235, 235);
[bgView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(bgView).offset(15);
make.right.equalTo(bgView.mas_right);
make.top.equalTo(titleLabel.mas_bottom);
make.height.mas_equalTo(0.5);
}];
}
if (i == 0)
{
UIButton *endTimeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextColor normalText:self.modelDic.count > 0 ? self.modelDic[@"e"] : @"17:00" click:^(id x) {
[UICommon resignKeyboard];
[BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:@"选择时间" selectValue:self.endTimeBtn.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
[self.endTimeBtn setTitle:selectValue forState:0];
}];
}];
endTimeBtn.layer.borderWidth = 0.5;
endTimeBtn.layer.borderColor = KKGrey219.CGColor;
endTimeBtn.layer.cornerRadius = Adapted(16);
self.endTimeBtn = endTimeBtn;
[bgView addSubview:endTimeBtn];
[endTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(bgView.mas_right).inset(15);
make.centerY.equalTo(titleLabel);
make.size.mas_equalTo(CGSizeMake(Adapted(60), Adapted(32)));
}];
UIImageView *line1 = [UIImageView new];
line1.backgroundColor = RGB(235, 235, 235);
[bgView addSubview:line1];
[line1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(endTimeBtn.mas_left).inset(8);
make.centerY.equalTo(endTimeBtn);
make.size.mas_equalTo(CGSizeMake(30, 1));
}];
UIButton *startTimeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextColor normalText:self.modelDic.count > 0 ? self.modelDic[@"s"] : @"08:00" click:^(id x) {
[UICommon resignKeyboard];
[BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:@"选择时间" selectValue:self.startTimeBtn.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
[self.startTimeBtn setTitle:selectValue forState:0];
}];
}];
startTimeBtn.layer.borderWidth = 0.5;
startTimeBtn.layer.borderColor = KKGrey219.CGColor;
startTimeBtn.layer.cornerRadius = Adapted(16);
self.startTimeBtn = startTimeBtn;
[bgView addSubview:startTimeBtn];
[startTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(line1.mas_left).inset(8);
make.centerY.equalTo(titleLabel);
make.size.mas_equalTo(CGSizeMake(Adapted(60), Adapted(32)));
}];
}
else
{
if (self.modelDic.count > 0)
self.btnArr = [self getWeekArr:self.modelDic[@"w"]];
else
self.btnArr = [[NSMutableArray alloc] initWithArray:@[@"1",@"1",@"1",@"1",@"1",@"0",@"0"]];
for (int j = 0; j < timeArr.count; j++)
{
CGRect rect = [timeArr[j] boundingRectWithSize:CGSizeMake(MAXFLOAT, Adapted(32)) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FontADA_(13)} context:nil];
CGFloat ww = 32;
if (rect.size.width > 32)
ww = rect.size.width+10;
UIButton *button = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextColor normalText:timeArr[j] click:^(UIButton *btn) {
btn.selected = !btn.selected;
btn.backgroundColor = btn.selected ? mainColor : KKClearColor;
btn.layer.borderColor = btn.selected ? mainColor.CGColor : KKGrey219.CGColor;
NSString *str = btn.selected ? @"1" : @"0";
[self.btnArr replaceObjectAtIndex:btn.tag withObject:str];
NSLog(@"%@",self.btnArr);
}];
if (self.modelDic.count > 0)
button.selected = [self.btnArr[j] isEqualToString:@"1"] ? YES : NO;
else
button.selected = j < 5 ? YES : NO;
button.tag = j;
button.layer.borderWidth = 0.5;
button.layer.borderColor = button.selected ? mainColor.CGColor : KKGrey219.CGColor;
button.layer.cornerRadius = Adapted(16);
button.backgroundColor = button.selected ? mainColor : KKClearColor;
[button setTitleColor:KKTextColor forState:UIControlStateNormal];
[button setTitleColor:KKWhiteColorColor forState:UIControlStateSelected];
[bgView addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(titleLabel);
make.size.mas_equalTo(CGSizeMake(Adapted(ww), Adapted(32)));
make.left.equalTo(titleLabel.mas_right).offset(Adapted(20)+Adapted(10)*j+Adapted(ww)*j);
}];
}
}
}
UILabel *titleLabel = [UICommon ui_myLabel:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(14) textColor:RGB(163, 163, 163) text:@"" Radius:0];
titleLabel.text = @"提示:设置使用时段,APP将只能在该时段进行使用,其他时间将无法使用。";
[self.view addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view).inset(5);
make.top.equalTo(bgView.mas_bottom).offset(20);
make.height.mas_equalTo(60);
}];
}
- (NSMutableArray *)getWeekArr:(NSString *)string
{
NSMutableArray *weekArr = [NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@"",@"",@""]];
[string enumerateSubstringsInRange:NSMakeRange(0, string.length)
options:NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop)
{
[weekArr replaceObjectAtIndex:substringRange.location withObject:substring];
}];
return weekArr;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end