Files
peko-ios/YuMi/Modules/YMLogin/View/CustomView/LoginForgetEditView.m
2023-12-07 19:44:52 +08:00

208 lines
6.6 KiB
Objective-C

//
// LoginForgetEditView.m
// xplan-ios
//
// Created by 冯硕 on 2021/9/10.
//
#import "LoginForgetEditView.h"
///第三方
#import <Masonry/Masonry.h>
///Tool
@interface LoginForgetEditView()
///容器
@property (nonatomic,strong) UIStackView *stackView;
///倒计时
@property (nonatomic, strong) UILabel *cutdownLabel;
///选择区号
@property (nonatomic,strong) UILabel *codeView;
/** textField */
@property (nonatomic, strong) XPTextField *textField;
/** rightButton */
@property (nonatomic, strong) UIButton *rightButton;
/** 验证码 */
@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 = UIColorFromRGB(0xF0F5F6);
self.layer.masksToBounds = YES;
self.layer.cornerRadius = kGetScaleWidth(24);
[self addSubview:self.stackView];
[self.stackView addArrangedSubview:self.codeView];
[self.stackView addArrangedSubview:self.textField];
[self.stackView addArrangedSubview:self.rightButton];
[self.stackView addArrangedSubview:self.cutdownLabel];
[self.stackView addArrangedSubview:self.authCodeButton];
}
- (void)initConstrations {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(20));
make.trailing.mas_equalTo(-kGetScaleWidth(20));
make.top.bottom.equalTo(self);
}];
[self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_lessThanOrEqualTo(kGetScaleWidth(70));
}];
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.codeView.mas_trailing).mas_offset(10);
}];
[self.authCodeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_lessThanOrEqualTo(kGetScaleWidth(120));
}];
[self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(24));
}];
[self.cutdownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_lessThanOrEqualTo(kGetScaleWidth(120));
}];
}
#pragma mark - getters and setters
- (void)setType:(LoginForgetEditViewType)type {
switch (type) {
case LoginForgetEditViewTypeNormal:
self.codeView.hidden = NO;
self.rightButton.hidden = YES;
self.authCodeButton.hidden = YES;
self.cutdownLabel.hidden = YES;
self.textField.isValidation = YES;
break;
case LoginForgetEditViewTypeSms:
self.authCodeButton.hidden = NO;
self.rightButton.hidden = YES;
self.cutdownLabel.hidden = YES;
self.codeView.hidden = YES;
self.textField.isValidation = YES;
break;
case LoginForgetEditViewTypePassword:
self.authCodeButton.hidden = YES;
self.cutdownLabel.hidden = YES;
self.codeView.hidden = YES;
self.rightButton.hidden = NO;
self.textField.isValidation = NO;
break;
default:
break;
}
}
-(NSMutableAttributedString *)getChooseCodeText:(NSString *)code{
NSMutableAttributedString *codeAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ ",code] attributes:@{NSFontAttributeName:kFontSemibold(15),NSForegroundColorAttributeName:[DJDKMIMOMColor inputTextColor]}];
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
UIImage *iconImage = [UIImage imageNamed:@"login_arrow"];;
attachment.bounds = CGRectMake(0, roundf(self.codeView.font.capHeight - iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height);
attachment.image = iconImage;
[codeAtt appendAttributedString:[NSMutableAttributedString attributedStringWithAttachment:attachment]];
return codeAtt;
}
-(void)setAreaCode:(NSString *)areaCode{
_areaCode = areaCode;
_codeView.attributedText = [self getChooseCodeText:_areaCode];
}
- (void)setPlaceholder:(NSString *)placeholder {
_placeholder = placeholder;
if (_placeholder) {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
NSDictionary *dic = @{
NSParagraphStyleAttributeName:style,
NSFontAttributeName:kFontRegular(15),
NSForegroundColorAttributeName:[DJDKMIMOMColor disableButtonTextColor]};
if (placeholder == nil || placeholder.length == 0) {
placeholder = @"";
}
self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:dic];
}
}
#pragma mark -懒加载
- (UILabel *)codeView{
if (!_codeView){
_codeView = [UILabel new];
_codeView.userInteractionEnabled = YES;
NSString *code = [NSString getCountryCode];
_codeView.attributedText = [self getChooseCodeText: code];
}
return _codeView;
}
- (XPTextField *)textField {
if (!_textField) {
_textField = [[XPTextField alloc]initWithFrame:CGRectZero];
_textField.font = kFontRegular(15);
_textField.textColor = [DJDKMIMOMColor inputTextColor];
_textField.adjustsFontSizeToFitWidth = YES;
}
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;
}
- (UILabel *)cutdownLabel {
if (!_cutdownLabel) {
_cutdownLabel = [[UILabel alloc] init];
_cutdownLabel.textAlignment = NSTextAlignmentRight;
_cutdownLabel.font = kFontRegular(15);
_cutdownLabel.textColor = UIColorFromRGB(0x9168FA);
_cutdownLabel.hidden = NO;
}
return _cutdownLabel;
}
- (UIButton *)authCodeButton {
if (!_authCodeButton) {
_authCodeButton = [UIButton buttonWithType:UIButtonTypeCustom];
_authCodeButton.titleLabel.font = kFontRegular(15);
[_authCodeButton setTitle:YMLocalizedString(@"LoginForgetEditView0") forState:UIControlStateNormal];
_authCodeButton.titleLabel.numberOfLines = 0;
_authCodeButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[_authCodeButton setTitleColor:[DJDKMIMOMColor inputTextColor] 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