// // YOUPAIMessageTemplateName.m // MSYOUPAI // // Created by admin on 2022/3/16. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAIMessageTemplateName.h" #import "IQKeyboardManager.h" #import "YYKit.h" @interface YOUPAIMessageTemplateName () @end @implementation YOUPAIMessageTemplateName - (void)viewDidLoad { [super viewDidLoad]; [self youpaifmaketUI]; [self youpaifMakeLayout]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[IQKeyboardManager sharedManager] setEnable:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[IQKeyboardManager sharedManager] setEnable:NO]; } -(UILabel *)youpaipnameLabel{ if(_youpaipnameLabel == nil){ _youpaipnameLabel = [UILabel new]; _youpaipnameLabel.textAlignment = NSTextAlignmentCenter; _youpaipnameLabel.text = @"模版备注"; } return _youpaipnameLabel; } -(UITextField *)youpaiptextField{ if(_youpaiptextField == nil){ _youpaiptextField = [UITextField new]; _youpaiptextField.placeholder = @"请输入模版名称"; _youpaiptextField.delegate = self; _youpaiptextField.textAlignment = NSTextAlignmentCenter; _youpaiptextField.backgroundColor = LZFAFAFCColor; [_youpaiptextField ms_radius:6]; } return _youpaiptextField; } -(UILabel *)youpaipremarkLab{ if(_youpaipremarkLab == nil){ _youpaipremarkLab = [UILabel new]; _youpaipremarkLab.text = @"0/15"; _youpaipremarkLab.textAlignment = NSTextAlignmentRight; _youpaipremarkLab.textColor = LZA3AABEColor; _youpaipremarkLab.font = LCFont12; } return _youpaipremarkLab; } -(UIButton *)cancelBtn{ if (_cancelBtn == nil){ _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_cancelBtn setBackgroundColor:[UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(135, 49) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1]]]; @weakify(self) [_cancelBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) { @strongify(self) [self dismissViewControllerAnimated:true completion:^{}]; }]; [_cancelBtn setTitle:@"取消" forState:0]; [_cancelBtn setTitleColor:LZ273145Color forState:0]; [_cancelBtn setBackgroundColor:LZF5F4F7Color]; _cancelBtn.layer.cornerRadius = 24; _cancelBtn.layer.masksToBounds = YES; _cancelBtn.titleLabel.font = LCFont(14); } return _cancelBtn; } -(UIButton *)confirmBtn{ if(_confirmBtn == nil){ _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_confirmBtn setBackgroundColor:[UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(135, 49) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1]]]; @weakify(self) [_confirmBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) { @strongify(self) [self dismissViewControllerAnimated:true completion:^{ if (self.commitBlock){ self.commitBlock(self); } }]; }]; [_confirmBtn setTitle:@"确定" forState:0]; [_confirmBtn setTitleColor:HexColorFromRGB(0xffffff) forState:0]; [_confirmBtn setBackgroundColor:[UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((self.vWidth-42)/2.0, 48) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1]]]; _confirmBtn.layer.cornerRadius = 24; _confirmBtn.layer.masksToBounds = YES; _confirmBtn.titleLabel.font = LCFont(14); } return _confirmBtn; } -(void)youpaifmaketUI{ [self.baseView addSubview:self.youpaipnameLabel]; [self.baseView addSubview:self.youpaiptextField]; [self.baseView addSubview:self.youpaipremarkLab]; [self.baseView addSubview:self.cancelBtn]; [self.baseView addSubview:self.confirmBtn]; [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条 [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; // [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES; } -(void)youpaifMakeLayout{ [_youpaipnameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.right.mas_equalTo(-14); make.top.mas_equalTo(20); }]; [_youpaiptextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.right.mas_equalTo(-14); make.top.mas_equalTo(self.youpaipnameLabel.mas_bottom).mas_offset(20); make.height.mas_equalTo(49); }]; [_youpaipremarkLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.right.mas_equalTo(-14); make.top.mas_equalTo(self.youpaiptextField.mas_bottom).mas_offset(6); make.height.mas_equalTo(49); }]; [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.youpaiptextField); make.size.mas_equalTo(CGSizeMake(135, 49)); make.top.mas_equalTo(self.youpaipremarkLab.mas_bottom).mas_offset(6); }]; [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.youpaiptextField); make.size.mas_equalTo(CGSizeMake(135, 49)); make.top.mas_equalTo(self.youpaipremarkLab.mas_bottom).mas_offset(6); }]; } -(void)textFieldDidChangeSelection:(UITextField *)textField{ if (textField.text.length > 15) { textField.text = [textField.text substringToIndex:15]; } _youpaipremarkLab.text = [NSString stringWithFormat:@"%zd/15",textField.text.length]; } //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // UITouch *touch = [touches.allObjects lastObject]; // if (touch.view == self.view && self.isTouchDismiss) { // [self.view endEditing:true]; // } //} @end