// // XPMineModifPayPwdView.m // xplan-ios // // Created by 冯硕 on 2021/9/18. // #import "XPMineModifPayPwdView.h" ///Third #import ///Tool #import "UIButton+EnlargeTouchArea.h" @interface XPMineModifPayPwdView () ///输入框 @property (nonatomic,strong) UITextField *contentTextField; ///控制显示或者隐藏 @property (nonatomic,strong) UIButton *commandButton; ///背景 @property (nonatomic,strong) UIView * bgView; @end @implementation XPMineModifPayPwdView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Response - (void)onClickHiddenBtn:(UIButton *)btn { btn.selected = !btn.selected; self.contentTextField.secureTextEntry = !self.contentTextField.secureTextEntry; } #pragma mark - Private Method - (void)initSubViews { self.backgroundColor = [UIColor clearColor]; [self addSubview:self.bgView]; [self.bgView addSubview:self.contentTextField]; [self.bgView addSubview:self.commandButton]; } - (void)initSubViewConstraints { [self mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(48); }]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.equalTo(self); make.leading.mas_offset(15); make.trailing.mas_equalTo(-15); }]; [self.contentTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(20); make.trailing.mas_equalTo(-54); make.top.bottom.mas_equalTo(self.bgView); }]; [self.commandButton mas_makeConstraints:^(MASConstraintMaker *make) { make.trailing.mas_equalTo(-20); make.width.height.mas_equalTo(24); make.centerY.mas_equalTo(self.contentTextField); make.leading.mas_equalTo(self.contentTextField.mas_trailing).offset(10); }]; } #pragma mark - Getters And Setters - (void)setPlaceholder:(NSString *)placeholder { _placeholder = placeholder; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; self.contentTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSFontAttributeName : self.contentTextField.font, NSForegroundColorAttributeName : [DJDKMIMOMColor disableButtonTextColor], NSParagraphStyleAttributeName: style}]; } - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; _bgView.backgroundColor = UIColorFromRGB(0xF0F5F6); _bgView.layer.cornerRadius = 24; _bgView.layer.masksToBounds = YES; } return _bgView; } - (UITextField *)contentTextField { if (!_contentTextField) { _contentTextField = [[UITextField alloc] init]; _contentTextField.secureTextEntry = YES; _contentTextField.font = [UIFont systemFontOfSize:15]; _contentTextField.textColor = [DJDKMIMOMColor inputTextColor]; _contentTextField.tintColor = [DJDKMIMOMColor appMainColor]; } return _contentTextField; } - (UIButton *)commandButton { if (!_commandButton) { _commandButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_commandButton setEnlargeEdgeWithTop:20 right:20 bottom:20 left:20]; [_commandButton addTarget:self action:@selector(onClickHiddenBtn:) forControlEvents:UIControlEventTouchUpInside]; [_commandButton setImage:[UIImage imageNamed:@"mine_setting_modif_pay_pwd_hidden"] forState:UIControlStateNormal]; [_commandButton setImage:[UIImage imageNamed:@"mine_setting_modif_pay_pwd_show"] forState:UIControlStateSelected]; _commandButton.titleLabel.font = [UIFont systemFontOfSize:12]; [_commandButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } return _commandButton; } @end