Files
yinmeng-ios/xplan-ios/Main/Login/View/CustomView/LoginForgetEditView.m
2021-09-10 17:04:18 +08:00

150 lines
4.2 KiB
Objective-C

//
// LoginForgetEditView.m
// xplan-ios
//
// Created by 冯硕 on 2021/9/10.
//
#import "LoginForgetEditView.h"
///第三方
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
@interface LoginForgetEditView()
///
@property (nonatomic,strong) UIStackView *stackView;
/** textField */
@property (nonatomic, strong) UITextField *textField;
/** rightButton */
@property (nonatomic, strong) UIButton *rightButton;
/** bottomLineView */
@property (nonatomic, strong) UIView *bottomLineView;
/** 验证码 */
@property (nonatomic, strong) UIButton *authCodeButton;
@end
@implementation LoginForgetEditView
#pragma mark - life cycle
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initView];
[self initConstrations];
}
return self;
}
#pragma mark - private method
- (void)initView {
self.backgroundColor = [ThemeColor appCellBackgroundColor];
[self addSubview:self.stackView];
[self addSubview:self.bottomLineView];
[self.stackView addArrangedSubview:self.textField];
[self.stackView addArrangedSubview:self.rightButton];
[self.stackView addArrangedSubview:self.authCodeButton];
}
- (void)initConstrations {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.authCodeButton);
make.left.right.mas_equalTo(self.bottomLineView);
make.top.bottom.mas_equalTo(self);
}];
[self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self).inset(25);
make.bottom.mas_equalTo(0);
make.height.mas_equalTo(0.5);
}];
}
#pragma mark - getters and setters
- (void)setType:(LoginForgetEditViewType)type {
switch (type) {
case LoginForgetEditViewTypeNormal:
self.rightButton.hidden = YES;
self.authCodeButton.hidden = YES;
break;
case LoginForgetEditViewTypeSms:
self.authCodeButton.hidden = NO;
self.rightButton.hidden = YES;
break;
case LoginForgetEditViewTypePassword:
self.authCodeButton.hidden = YES;
self.rightButton.hidden = NO;
break;
default:
break;
}
}
- (void)setPlaceholder:(NSString *)placeholder {
_placeholder = placeholder;
if (_placeholder) {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.alignment = NSTextAlignmentLeft;
NSDictionary *dic = @{
NSParagraphStyleAttributeName:style,
NSFontAttributeName:[UIFont systemFontOfSize:14],
NSForegroundColorAttributeName:[ThemeColor secondTextColor]};
if (placeholder == nil || placeholder.length == 0) {
placeholder = @"";
}
self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:dic];
}
}
- (UITextField *)textField {
if (!_textField) {
_textField = [[UITextField alloc] init];
_textField.font = [UIFont systemFontOfSize:14];
_textField.textColor = [ThemeColor mainTextColor];
_textField.keyboardType = UIKeyboardTypeNumberPad;
_textField.tintColor = [ThemeColor appMainColor];
}
return _textField;
}
- (UIButton *)rightButton {
if (!_rightButton) {
_rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_rightButton setImage:[UIImage imageNamed:@"login_forget_password_hidden"] forState:UIControlStateNormal];
[_rightButton setImage:[UIImage imageNamed:@"login_forget_password_show"] forState:UIControlStateSelected];
}
return _rightButton;
}
- (UIView *)bottomLineView {
if (!_bottomLineView) {
_bottomLineView = [[UIView alloc] init];
_bottomLineView.backgroundColor = [ThemeColor partingLineColor];
}
return _bottomLineView;
}
- (UIButton *)authCodeButton {
if (!_authCodeButton) {
_authCodeButton = [UIButton buttonWithType:UIButtonTypeCustom];
_authCodeButton.titleLabel.font = [UIFont systemFontOfSize:14];
[_authCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
[_authCodeButton setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateDisabled];
[_authCodeButton setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
}
return _authCodeButton;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 10;
}
return _stackView;
}
@end