Files
yinmeng-ios/xplan-ios/Main/Login/View/CustomView/LoginInputView.m

114 lines
2.9 KiB
Mathematica
Raw Normal View History

2021-09-08 21:29:47 +08:00
//
// LoginInputView.m
// xplan-ios
//
// Created by on 2021/9/8.
//
#import "LoginInputView.h"
///
#import <Masonry/Masonry.h>
///
#import "ThemeColor.h"
2021-09-08 21:29:47 +08:00
@interface LoginInputView () <UITextFieldDelegate>
2021-09-08 21:29:47 +08:00
///
@property (nonatomic,strong) UIStackView *stackView;
///
@property (nonatomic,strong) UILabel *titleLabel;
///
@property (nonatomic,strong) UITextField *textField;
@end
@implementation LoginInputView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.stackView];
[self.stackView addArrangedSubview:self.titleLabel];
[self.stackView addArrangedSubview:self.textField];
}
- (void)initSubViewConstraints {
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(50);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self).offset(15);
make.right.top.bottom.mas_equalTo(self);
}];
}
#pragma mark - Getters And Setters
- (void)setPlaceHolder:(NSString *)placeHolder {
_placeHolder = placeHolder;
if (_placeHolder) {
self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:_placeHolder attributes:@{NSForegroundColorAttributeName: [ThemeColor secondTextColor], NSFontAttributeName:[UIFont systemFontOfSize:14]}];
}
}
- (void)setTitle:(NSString *)title {
_title = title;
if (_title) {
self.titleLabel.text = _title;
2021-09-08 21:29:47 +08:00
}
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
2021-09-08 21:29:47 +08:00
_stackView.spacing = 0;
}
return _stackView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:18];
_titleLabel.textColor = [ThemeColor mainTextColor];
2021-09-08 21:29:47 +08:00
_titleLabel.text = @"+86";
}
return _titleLabel;
}
- (UITextField *)textField {
if (!_textField) {
_textField = [[UITextField alloc] init];
_textField.textColor = [ThemeColor mainTextColor];
2021-09-08 21:29:47 +08:00
_textField.font = [UIFont systemFontOfSize:18.f];
_textField.borderStyle = UITextBorderStyleNone;
_textField.keyboardType = UIKeyboardTypeNumberPad;
_textField.tintColor = [ThemeColor appMainColor];
2021-09-09 18:15:17 +08:00
_textField.backgroundColor = [UIColor clearColor];
_textField.delegate = self;
2021-09-08 21:29:47 +08:00
}
return _textField;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return textField.text.length <= self.maxLength;
}
- (void)textFieldDidChangeSelection:(UITextField *)textField {
textField.text = [textField.text substringToIndex:MIN(textField.text.length, self.maxLength)];
}
2021-09-08 21:29:47 +08:00
@end