162 lines
5.3 KiB
Mathematica
162 lines
5.3 KiB
Mathematica
![]() |
//
|
||
|
// YMLoginInputView.m
|
||
|
// YUMI
|
||
|
//
|
||
|
// Created by XY on 2023/2/14.
|
||
|
//
|
||
|
|
||
|
#import "XPLoginInputView.h"
|
||
|
#import "DJDKMIMOMColor.h"
|
||
|
#import <Masonry.h>
|
||
|
#import <ReactiveObjC.h>
|
||
|
|
||
|
@interface XPLoginInputView()
|
||
|
|
||
|
@property (nonatomic, strong) dispatch_source_t timer;
|
||
|
|
||
|
@property (nonatomic,strong) UIImageView *areaImageView;
|
||
|
@end
|
||
|
|
||
|
@implementation XPLoginInputView
|
||
|
|
||
|
- (instancetype)initWithFrame:(CGRect)frame {
|
||
|
self = [super initWithFrame:frame];
|
||
|
if (self) {
|
||
|
self.backgroundColor = UIColor.clearColor;
|
||
|
self.layer.cornerRadius = 66.0/2.0;
|
||
|
self.layer.borderWidth = 1;
|
||
|
self.layer.borderColor = [UIColor.whiteColor colorWithAlphaComponent:0.2].CGColor;
|
||
|
|
||
|
[self createUI];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)createUI {
|
||
|
UIStackView *stackView = [[UIStackView alloc] init];
|
||
|
stackView.axis = UILayoutConstraintAxisHorizontal;
|
||
|
stackView.distribution = UIStackViewDistributionFill;
|
||
|
stackView.alignment = UIStackViewAlignmentCenter;
|
||
|
stackView.spacing = 5;
|
||
|
[self addSubview:stackView];
|
||
|
|
||
|
|
||
|
UIImageView * areaImageView = [[UIImageView alloc] init];
|
||
|
areaImageView.userInteractionEnabled = YES;
|
||
|
areaImageView.image = [UIImage imageNamed:@"login_area_arrow"];
|
||
|
areaImageView.userInteractionEnabled = NO;
|
||
|
|
||
|
/// 区号
|
||
|
UIButton *areaCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[areaCodeBtn setTitle:@"+852" forState:UIControlStateNormal];
|
||
|
[areaCodeBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
||
|
areaCodeBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
|
||
|
_areaCodeBtn = areaCodeBtn;
|
||
|
areaCodeBtn.userInteractionEnabled = NO;
|
||
|
|
||
|
UIStackView *areaStackView = [[UIStackView alloc] init];
|
||
|
areaStackView.axis = UILayoutConstraintAxisHorizontal;
|
||
|
areaStackView.distribution = UIStackViewDistributionFill;
|
||
|
areaStackView.alignment = UIStackViewAlignmentCenter;
|
||
|
areaStackView.spacing = 2;
|
||
|
|
||
|
|
||
|
UIButton *areaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[areaBtn addTarget:self action:@selector(areaChooseClicked) forControlEvents:UIControlEventTouchUpInside];
|
||
|
[areaStackView addSubview:areaBtn];
|
||
|
|
||
|
[areaStackView addArrangedSubview:areaCodeBtn];
|
||
|
[areaStackView addArrangedSubview:areaImageView];
|
||
|
|
||
|
[stackView addArrangedSubview:areaStackView];
|
||
|
self.areaStackView = areaStackView;
|
||
|
|
||
|
|
||
|
/// 输入框
|
||
|
UITextField *inputTextField = [[UITextField alloc] init];
|
||
|
inputTextField.textColor = UIColor.whiteColor;
|
||
|
inputTextField.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
|
||
|
[stackView addArrangedSubview:inputTextField];
|
||
|
self.inputTextField = inputTextField;
|
||
|
/// 获取验证码
|
||
|
UIButton *smsCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[smsCodeBtn setTitle:YMLocalizedString(@"XPLoginInputView0") forState:UIControlStateNormal];
|
||
|
[smsCodeBtn setTitleColor:UIColorFromRGB(0xFB486A) forState:UIControlStateNormal];
|
||
|
smsCodeBtn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
|
||
|
[smsCodeBtn addTarget:self action:@selector(smsCodeBtnClicked) forControlEvents:UIControlEventTouchUpInside];
|
||
|
[stackView addArrangedSubview:smsCodeBtn];
|
||
|
self.smsCodeBtn = smsCodeBtn;
|
||
|
|
||
|
[stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(15);
|
||
|
make.right.mas_equalTo(-15);
|
||
|
make.top.bottom.mas_equalTo(0);
|
||
|
}];
|
||
|
|
||
|
|
||
|
[areaImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo(18);
|
||
|
make.height.mas_equalTo(18);
|
||
|
}];
|
||
|
|
||
|
[areaCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo(50);
|
||
|
make.height.mas_equalTo(stackView);
|
||
|
}];
|
||
|
[inputTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo(stackView);
|
||
|
}];
|
||
|
[smsCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo(80);
|
||
|
make.height.mas_equalTo(stackView);
|
||
|
}];
|
||
|
|
||
|
[areaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.edges.mas_equalTo(areaStackView);
|
||
|
}];
|
||
|
|
||
|
|
||
|
self.areaStackView.hidden = YES;
|
||
|
self.smsCodeBtn.hidden = YES;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
- (void)smsCodeBtnClicked {
|
||
|
if (self.delegate && [self.delegate respondsToSelector:@selector(smsCodeAction)]) {
|
||
|
[self.delegate smsCodeAction];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)areaChooseClicked {
|
||
|
if (self.delegate && [self.delegate respondsToSelector:@selector(areaListAction)]) {
|
||
|
[self.delegate areaListAction];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//开启倒计时
|
||
|
- (void)fireTimer {
|
||
|
__block NSInteger count = 60;
|
||
|
dispatch_queue_t queue = dispatch_get_main_queue();
|
||
|
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
||
|
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
|
||
|
@weakify(self);
|
||
|
dispatch_source_set_event_handler(timer, ^{
|
||
|
@strongify(self);
|
||
|
count--;
|
||
|
if (count < 0) {
|
||
|
[self.smsCodeBtn setTitle:YMLocalizedString(@"XPLoginInputView1") forState:UIControlStateNormal];
|
||
|
self.smsCodeBtn.userInteractionEnabled = YES;
|
||
|
dispatch_cancel(self.timer);
|
||
|
}else{
|
||
|
[self.smsCodeBtn setTitle:[NSString stringWithFormat:@"%lds",count] forState:UIControlStateNormal];
|
||
|
self.smsCodeBtn.userInteractionEnabled = NO;
|
||
|
}
|
||
|
});
|
||
|
dispatch_resume(timer);
|
||
|
self.timer = timer;
|
||
|
}
|
||
|
|
||
|
@end
|