cdts/xdts-ios 3/TreeHole/Code/Utility/InputView/AlertInputView.m
2023-07-27 09:20:00 +08:00

187 lines
7.9 KiB
Objective-C

//
// AlertInputView.m
// Meet
//
// Created by mambaxie on 2021/1/10.
//
#import "AlertInputView.h"
#import "FSTextInputView.h"
#import "PYInputView.h"
#import "MTAlertView.h"
#import <Toast/Toast.h>
@implementation AlertInputView
+ (MTAlertView *)showWithTitle:(NSString *)title content:(NSString *)content maxLength:(NSUInteger)maxLength action:(BOOL(^)(NSString *content))action {
return [self showWithTitle:title content:content maxLength:maxLength isCheck:NO action:action];
}
+ (MTAlertView *)showCheckPasswordWithTitle:(NSString *)title content:(NSString *)content maxLength:(NSUInteger)maxLength action:(BOOL (^)(NSString * _Nonnull))action {
return [self showWithTitle:title content:content maxLength:maxLength isCheck:YES action:action];
}
+ (MTAlertView *)showWithTitle:(NSString *)title content:(nullable NSString *)content maxLength:(NSUInteger)maxLength isCheck:(BOOL)isCheck action:(BOOL(^)(NSString *content))action {
MTAlertView *alertView = [MTAlertView alloc];
WeakSelf(alertView);
[alertView initWithSetupBlock:^(MTAlertViewConfig *config) {
config.otherTitle = @"确定";
if (!isCheck) {
config.cancelTitle = @"取消";
}
UIView* bgView = [[UIView alloc] init];
bgView.width = SCREEN_WIDTH;
bgView.height = SCREEN_HEIGHT;
bgView.backgroundColor = [UIColor blackColor];
UIView *customView = [[UIView alloc] init];
customView.width = kMTAlertContentSizeDefaultWidth;
customView.backgroundColor = COLOR_WITH_RGB(0x222436);
customView.layer.cornerRadius = 8;
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = MT_FONT_REGULAR_SIZE(16);
titleLabel.textColor = [UIColor whiteColor];
// titleLabel.backgroundColor = UIColor.redColor;
titleLabel.y = FIX_SIZE(30);
titleLabel.text = title;
[titleLabel sizeToFit];
customView.width = kMTAlertContentSizeDefaultWidth;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.width = customView.width;
[customView addSubview:titleLabel];
UIView *inputView = [self createInputViewWithContent:content Placeholder:[NSString stringWithFormat:@"请输入%lu位数字密码", (unsigned long)maxLength] maxWidth:customView.width maxLength:maxLength];
UITextField *textField = inputView.subviews.firstObject;
dispatch_async(dispatch_get_main_queue(), ^{
[textField.window makeKeyWindow];
});
weakalertView.textField = textField;
inputView.y = titleLabel.bottom + FIX_SIZE(15);
[customView addSubview:inputView];
customView.height = inputView.bottom + FIX_SIZE(30);
config.customView = customView;
if ([title isEqualToString:@"验证密码锁"]) {
[[ZcqVender theTopviewControler].view addSubview:bgView];
}else{
}
config.otherHandler = ^(MTAlertButton *button) {
if (action) {
BOOL succeed = action(textField.text);
if (!succeed) {
[button setTag:MTNO_DISMISS_TAG];
} else {
if ([title isEqualToString:@"验证密码锁"]) {
[bgView removeFromSuperview];
}else{
}
[button setTag:0];
}
}
};
config.cancelHandler = ^(MTAlertButton *button) {
// [inputView.textview endEditing:NO];
};
config.otherButtonType = MTAlertButtonTypeDefaultTheme;
}];
[alertView show];
return alertView;
}
+ (UIView *)createInputViewWithContent:(NSString *)content Placeholder:(NSString *)placeholder maxWidth:(CGFloat)maxWidth maxLength:(NSUInteger)maxLength {
UIView *inputView = [[UIView alloc] init];
inputView.height = FIX_SIZE(52);
inputView.x = FIX_SIZE(20);
inputView.width = maxWidth - inputView.left * 2;
inputView.backgroundColor = COLOR_WITH_RGB(0x2D2F42);
inputView.layer.cornerRadius = FIX_SIZE(20);
inputView.layer.borderWidth = 0.5;
inputView.layer.borderColor = COLOR_WITH_RGB(0x979797).CGColor;
inputView.clipsToBounds = YES;
UITextField *textField = [[UITextField alloc] init];
textField.left = FIX_SIZE(17);
textField.height = inputView.height;
textField.width = inputView.width - textField.left * 2;
textField.font = MT_FONT_REGULAR_SIZE(13);
textField.text = content;
textField.textColor = [UIColor whiteColor];
NSMutableAttributedString *placeholderAttr = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{
NSFontAttributeName: textField.font,
NSForegroundColorAttributeName: COLOR_WITH_RGB(0xB3B3B3)
}];
[textField mt_setupLimitTextFieldWithBytesLength:maxLength delegate:nil];
[textField setAttributedPlaceholder:placeholderAttr];
textField.textColor = [UIColor whiteColor];
textField.keyboardType = UIKeyboardTypeNumberPad;
[inputView addSubview:textField];
return inputView;
}
+ (MTAlertView *)showChangePasswordWithTitle:(NSString *)title maxLength:(NSUInteger)maxLength action:(nonnull BOOL (^)(NSString * _Nonnull, NSString * _Nonnull))action {
MTAlertView *alertView = [MTAlertView alloc];
WeakSelf(alertView);
[alertView initWithSetupBlock:^(MTAlertViewConfig *config) {
config.otherTitle = @"确定";
config.cancelTitle = @"取消";
UIView *customView = [[UIView alloc] init];
customView.backgroundColor = COLOR_WITH_RGB(0x222436);
customView.layer.cornerRadius = 8;
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = MT_FONT_REGULAR_SIZE(16);
titleLabel.textColor = [UIColor whiteColor];
// titleLabel.backgroundColor = UIColor.redColor;
titleLabel.y = FIX_SIZE(30);
titleLabel.text = title;
[titleLabel sizeToFit];
customView.width = kMTAlertContentSizeDefaultWidth;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.width = customView.width;
[customView addSubview:titleLabel];
UIView *inputView = [self createInputViewWithContent:nil Placeholder:@"输入旧密码" maxWidth:customView.width maxLength:maxLength];
UITextField *textField = inputView.subviews.firstObject;
[textField becomeFirstResponder];
dispatch_async(dispatch_get_main_queue(), ^{
[textField.window makeKeyWindow];
[textField becomeFirstResponder];
});
inputView.y = titleLabel.bottom + FIX_SIZE(15);
[customView addSubview:inputView];
UIView *inputView2 = [self createInputViewWithContent:nil Placeholder:[NSString stringWithFormat:@"请输入%lu位数字新密码", (unsigned long)maxLength] maxWidth:customView.width maxLength:maxLength];
UITextField *textField2 = inputView2.subviews.firstObject;
[textField2 becomeFirstResponder];
dispatch_async(dispatch_get_main_queue(), ^{
[textField2.window makeKeyWindow];
});
weakalertView.textField = textField2;
[customView addSubview:inputView];
[customView addSubview:inputView2];
inputView2.y = inputView.bottom + FIX_SIZE(10);
customView.height = inputView2.bottom + FIX_SIZE(30);
config.customView = customView;
config.otherHandler = ^(MTAlertButton *button) {
if (action) {
BOOL succeed = action(textField.text, textField2.text);
if (!succeed) {
[button setTag:MTNO_DISMISS_TAG];
} else {
[button setTag:0];
}
}
};
config.cancelHandler = ^(MTAlertButton *button) {
// [inputView.textview endEditing:NO];
};
config.otherButtonType = MTAlertButtonTypeDefaultTheme;
}];
[alertView show];
return alertView;
}
@end