// // YXYoungSetPwView.m // romantic // // Created by MAC on 2022/12/15. // Copyright © 2022 romantic. All rights reserved. // #import "YXYoungSetPwView.h" #import "YXYoungShenSuViewController.h" @interface YXYoungSetPwView () @property (nonatomic,copy) NSString *password; @end @implementation YXYoungSetPwView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setUI]; } return self; } - (void)setUI { self.backgroundColor = HEXCOLORA(0x000000, 0.5); UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 240, ScreenWidth-30, 248)]; baseView.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(ScreenWidth-30, 248) direction:FXGradientChangeDirectionVertical startColor:HEXCOLOR(0xDFFFF6) endColor:HEXCOLOR(0xFFFFFF)]; baseView.layer.cornerRadius = 16; [self addSubview:baseView]; self.nameLabel = [UILabel new]; [baseView addSubview:self.nameLabel]; self.nameLabel.frame = CGRectMake(0, 15, APPW-30 , 22); self.nameLabel.textAlignment = NSTextAlignmentCenter; self.nameLabel.font = YBBoldFont(18); self.nameLabel.text = @"请设置密码开启"; self.nameLabel.textColor = HEXCOLOR(0x333333); self.descLabel = [UILabel new]; [baseView addSubview:self.descLabel]; self.descLabel.frame = CGRectMake(0, CGRectGetMaxY(self.nameLabel.frame) + 10, APPW - 30, 20); self.descLabel.textAlignment = NSTextAlignmentCenter; self.descLabel.font = YBBoldFont(14); self.descLabel.text = @"开启青少年模式请输入密码"; self.descLabel.textColor = HEXCOLOR(0x333333); self.shensuLabel = [YYLabel new]; [baseView addSubview:self.shensuLabel]; self.shensuLabel.frame = CGRectMake(30, 50, APPW - 90, 50); self.shensuLabel.numberOfLines = 2; self.shensuLabel.hidden = YES; NSString *string = @"忘记密码可通过身份验证申诉申诉仅限成年人, \n未成年人请通知监护人完成"; NSMutableAttributedString *arrString = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName: YBBoldFont(14),NSForegroundColorAttributeName:HEXCOLOR(0x333333)}]; NSRange range = [string rangeOfString:@"身份验证申诉"]; [arrString yy_setColor:HEXCOLOR(0x0DFFB9) range:range]; WEAK_SELF [arrString yy_setTextHighlightRange:range color:HEXCOLOR(0x0DFFB9) backgroundColor:kClearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { NSLog(@"被点击"); [weakSelf removeFromSuperview]; YXYoungShenSuViewController *VC= [YXYoungShenSuViewController new]; [VC pushSelf]; }]; self.shensuLabel.attributedText = arrString; self.shensuLabel.textVerticalAlignment = YYTextVerticalAlignmentTop; self.shensuLabel.textAlignment = NSTextAlignmentCenter; CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new]; cellProperty.cellBgColorNormal = HEXCOLORA(0x0DFFB9, 1); cellProperty.cellBgColorSelected = HEXCOLORA(0x0DFFB9, 1); cellProperty.cellCursorColor = HEXCOLORA(0x333333, 1); // cellProperty.cellBorderColorNormal = HEXCOLORA(0x9249FF, 1); // cellProperty.cellBorderColorSelected = HEXCOLORA(0xFF5157, 1); // cellProperty.cellCursorWidth = 0; cellProperty.cellCursorHeight = 30; cellProperty.cornerRadius = 15; cellProperty.cellFont = YBBoldFont(24); cellProperty.cellTextColor = HEXCOLOR(0x333333); _boxInputView = [CRBoxInputView new]; _boxInputView.frame = CGRectMake(30, 105, APPW-30-60, 55); _boxInputView.codeLength = 4; // _boxInputView.mainCollectionView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10); _boxInputView.boxFlowLayout.itemSize = CGSizeMake(55, 55); _boxInputView.customCellProperty = cellProperty; [_boxInputView loadAndPrepareViewWithBeginEdit:YES]; [baseView addSubview:_boxInputView]; _boxInputViewTwo = [CRBoxInputView new]; _boxInputViewTwo.frame = CGRectMake(30, 105, APPW-30-60, 55); _boxInputViewTwo.codeLength = 4; // _boxInputViewTwo.mainCollectionView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10); _boxInputViewTwo.boxFlowLayout.itemSize = CGSizeMake(55, 55); _boxInputViewTwo.customCellProperty = cellProperty; [_boxInputViewTwo loadAndPrepareViewWithBeginEdit:YES]; _boxInputViewTwo.hidden = YES; [baseView addSubview:_boxInputViewTwo]; UIButton *cancelBtn = [ControlCreator createButton:baseView rect:CGRectMake(30, 190, 125, 44) text:@"取消" font:YBBoldFont(18) color:kWhiteColor backguoundColor:HEXCOLOR(0xCCCCCC) imageName:nil target:self action:@selector(cancelClick:)]; cancelBtn.layer.cornerRadius = 22; cancelBtn.layer.masksToBounds = YES; UIButton *confirmBtn = [ControlCreator createButton:baseView rect:CGRectMake(APPW-30-30-125, 190, 125, 44) text:@"确认" font:YBBoldFont(18) color:kBlackColor backguoundColor:kClearColor imageName:nil target:self action:@selector(confirmClick:)]; confirmBtn.layer.cornerRadius = 22; confirmBtn.layer.masksToBounds = YES; confirmBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(125, 44) direction:FXGradientChangeDirectionHorizontal startColor:HEXCOLOR(0x9FF6DD) endColor:HEXCOLOR(0x0DFFB9)]; } - (void)cancelClick:(UIButton *)sender { [self removeFromSuperview]; } - (void)confirmClick:(UIButton *)sender { WEAK_SELF if (self.type == 1) { if (self.password.length == 4) { NSDictionary *parms = @{ @"type":@"1", @"password":self.password, @"again_password":self.password }; [AFNetworkRequset.shared postRequestWithParams:parms Path:@"api/mode/open_teen_mode" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) { [HelpPageDefine showMessage:@"青少年模式已开启"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf removeFromSuperview]; [UIViewController.currentViewController.navigationController popToRootViewControllerAnimated:YES]; }); } Failure:^(id _Nonnull errorData) { }]; } }else if (self.type == 2) { if (self.password.length == 4) { NSDictionary *parms = @{ @"type":@"1", @"password":weakSelf.password, }; [AFNetworkRequset.shared postRequestWithParams:parms Path:@"api/mode/close_teen_mode" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) { [HelpPageDefine showMessage:@"青少年模式已关闭"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf removeFromSuperview]; [UIViewController.currentViewController.navigationController popToRootViewControllerAnimated:YES]; }); } Failure:^(id _Nonnull errorData) { }]; } }else if (self.type == 3) { if (self.password.length == 4) { NSDictionary *parms = @{ @"type":@"1", @"password":weakSelf.password, }; [AFNetworkRequset.shared postRequestWithParams:parms Path:@"api/mode/close_teen_mode" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) { [HelpPageDefine showMessage:@"青少年模式已关闭"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf removeFromSuperview]; [UIViewController.currentViewController.navigationController popToRootViewControllerAnimated:YES]; }); } Failure:^(id _Nonnull errorData) { }]; } } } - (void)setType:(int)type { _type = type; WEAK_SELF if (self.type == 1) { _nameLabel.text = @"请设置密码开启"; _descLabel.text = @"开启青少年模式请输入密码"; _shensuLabel.hidden = YES; _boxInputView.hidden = NO; _boxInputViewTwo.hidden = YES; _boxInputView.textDidChangeblock = ^(NSString * _Nullable text, BOOL isFinished) { if (isFinished == YES) { weakSelf.password = text; }else { weakSelf.password = @""; } }; } else if (_type == 2) { _nameLabel.text = @"请输入密码关闭"; _descLabel.text = @""; _shensuLabel.hidden = NO; _boxInputView.hidden = NO; _boxInputViewTwo.hidden = YES; _boxInputView.textDidChangeblock = ^(NSString * _Nullable text, BOOL isFinished) { if (isFinished == YES) { weakSelf.password = text; }else { weakSelf.password = @""; } }; }else if (_type == 3){ _nameLabel.text = @"请输入密码关闭"; _descLabel.text = @"关闭青少年模式请输入密码"; _shensuLabel.hidden = YES; _boxInputView.hidden = NO; _boxInputViewTwo.hidden = YES; _boxInputView.textDidChangeblock = ^(NSString * _Nullable text, BOOL isFinished) { if (isFinished == YES) { weakSelf.password = text; }else { weakSelf.password = @""; } }; } } @end