203 lines
6.2 KiB
Objective-C
203 lines
6.2 KiB
Objective-C
//
|
|
// XPMinePayPwdInputView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/18.
|
|
//
|
|
|
|
#import "XPMinePayPwdInputView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "UIButton+EnlargeTouchArea.h"
|
|
@interface XPMinePayPwdInputView()
|
|
///分割线
|
|
@property (nonatomic, strong) UIView *lineView;
|
|
///输入框
|
|
@property (nonatomic, strong) UITextField *contentTextField;
|
|
///状态按钮(隐藏显示密码、获取验证码、倒计时)
|
|
@property (nonatomic, strong) UIButton *statusButton;
|
|
///是否密文显示
|
|
@property (nonatomic, assign) BOOL isSecurity;
|
|
///内容长度限制
|
|
@property (nonatomic, assign) int contentLimit;
|
|
///键盘类型
|
|
@property (nonatomic, assign) UIKeyboardType keyboardType;
|
|
///提示文本
|
|
@property (nonatomic, strong) NSString *placeholder;
|
|
|
|
@end
|
|
|
|
|
|
@implementation XPMinePayPwdInputView
|
|
|
|
- (instancetype)init {
|
|
if (self = [super init]) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)initSubviews {
|
|
self.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
[self addSubview:self.contentTextField];
|
|
[self addSubview:self.statusButton];
|
|
[self addSubview:self.lineView];
|
|
[self makeConstriants];
|
|
}
|
|
|
|
- (void)makeConstriants {
|
|
|
|
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self).inset(25);
|
|
make.bottom.mas_equalTo(0);
|
|
make.height.mas_equalTo(0.5);
|
|
}];
|
|
|
|
[self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.lineView);
|
|
make.bottom.mas_equalTo(-10);
|
|
}];
|
|
|
|
[self.contentTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.statusButton);
|
|
make.left.mas_equalTo(self.lineView);
|
|
make.right.mas_equalTo(self.statusButton.mas_left).offset(-10);
|
|
make.height.mas_equalTo(44);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Event
|
|
|
|
- (void)edingtingChange {
|
|
if (self.contentLimit && self.contentTextField.text.length > self.contentLimit) {
|
|
self.contentTextField.text = [self.contentTextField.text substringToIndex:self.contentLimit];
|
|
}
|
|
}
|
|
|
|
- (void)onClickStatusButton:(UIButton *)sender {
|
|
if (self.type == XPPayPwdInputViewTypeVerification) {
|
|
!self.fetchVerificationHandler ?: self.fetchVerificationHandler();
|
|
return;
|
|
}
|
|
|
|
sender.selected = !sender.selected;
|
|
self.isSecurity = !sender.selected;
|
|
}
|
|
|
|
#pragma mark - Public
|
|
- (NSString *)contentText {
|
|
return self.contentTextField.text;
|
|
}
|
|
|
|
/// 验证码倒计时更新
|
|
/// @param seconds 秒数
|
|
- (void)verificationCountdownUpdate:(NSInteger)seconds {
|
|
if (self.type == XPPayPwdInputViewTypeVerification) {
|
|
[self.statusButton setTitle:[NSString stringWithFormat:@"%ld后重试", (long)seconds] forState:UIControlStateNormal];
|
|
[self.statusButton setEnabled:NO];
|
|
[self.statusButton setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
|
|
}
|
|
}
|
|
|
|
/// 验证码倒计时结束
|
|
- (void)verificationCountdownFinish {
|
|
if (self.type == XPPayPwdInputViewTypeVerification) {
|
|
[self.statusButton setTitle:@"重新发送" forState:UIControlStateNormal];
|
|
[self.statusButton setEnabled:YES];
|
|
[self.statusButton setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setType:(XPPayPwdInputViewType)type {
|
|
_type = type;
|
|
|
|
switch (type) {
|
|
case XPPayPwdInputViewTypePwd:
|
|
{
|
|
self.contentLimit = 6;
|
|
self.isSecurity = YES;
|
|
self.keyboardType = UIKeyboardTypeNumberPad;
|
|
self.placeholder = [NSString stringWithFormat:@"设置支付密码"];
|
|
}
|
|
break;
|
|
case XPPayPwdInputViewTypeRepeatPwd:
|
|
{
|
|
self.contentLimit = 6;
|
|
self.isSecurity = YES;
|
|
self.keyboardType = UIKeyboardTypeNumberPad;
|
|
self.placeholder = [NSString stringWithFormat:@"再次输支付密码"];
|
|
}
|
|
break;
|
|
case XPPayPwdInputViewTypeVerification:
|
|
{
|
|
self.contentLimit = 5;
|
|
self.isSecurity = NO;
|
|
self.keyboardType = UIKeyboardTypeNumberPad;
|
|
self.placeholder = @"请输入验证码";
|
|
|
|
[self.statusButton setTitle:@"获取验证码" forState:UIControlStateNormal];
|
|
[self.statusButton setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
|
|
[self.statusButton setImage:nil forState:UIControlStateNormal];
|
|
[self.statusButton setImage:nil forState:UIControlStateSelected];
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
- (void)setIsSecurity:(BOOL)isSecurity {
|
|
_isSecurity = isSecurity;
|
|
|
|
self.statusButton.selected = !isSecurity;
|
|
self.contentTextField.secureTextEntry = isSecurity;
|
|
}
|
|
|
|
- (void)setPlaceholder:(NSString *)placeholder {
|
|
_placeholder = placeholder;
|
|
self.contentTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSFontAttributeName : self.contentTextField.font, NSForegroundColorAttributeName : [ThemeColor secondTextColor]}];
|
|
}
|
|
|
|
- (void)setKeyboardType:(UIKeyboardType)keyboardType {
|
|
_keyboardType = keyboardType;
|
|
self.contentTextField.keyboardType = keyboardType;
|
|
}
|
|
|
|
- (UIView *)lineView {
|
|
if (!_lineView) {
|
|
_lineView = [[UIView alloc] init];
|
|
_lineView.backgroundColor = [ThemeColor dividerColor];
|
|
}
|
|
return _lineView;
|
|
}
|
|
|
|
- (UITextField *)contentTextField {
|
|
if (!_contentTextField) {
|
|
_contentTextField = [[UITextField alloc] init];
|
|
_contentTextField.secureTextEntry = YES;
|
|
_contentTextField.font = [UIFont systemFontOfSize:13];
|
|
_contentTextField.textColor = [ThemeColor mainTextColor];
|
|
[_contentTextField addTarget:self action:@selector(edingtingChange) forControlEvents:UIControlEventEditingChanged];
|
|
}
|
|
return _contentTextField;
|
|
}
|
|
|
|
- (UIButton *)statusButton {
|
|
if (!_statusButton) {
|
|
_statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_statusButton addTarget:self action:@selector(onClickStatusButton:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_statusButton setImage:[UIImage imageNamed:@"mine_setting_pay_password_hidden"] forState:UIControlStateNormal];
|
|
[_statusButton setImage:[UIImage imageNamed:@"mine_setting_pay_password_show"] forState:UIControlStateSelected];
|
|
_statusButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
[_statusButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
|
|
[_statusButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
|
|
[_statusButton setEnlargeEdgeWithTop:8 right:8 bottom:8 left:8];
|
|
}
|
|
return _statusButton;
|
|
}
|
|
|
|
@end
|