169 lines
5.8 KiB
Objective-C
169 lines
5.8 KiB
Objective-C
//
|
|
// YMMineUserInfoDesViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/9/23.
|
|
//
|
|
|
|
#import "XPMineUserInfoDesViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <SZTextView/SZTextView.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
|
|
static NSInteger maxCount = 60;
|
|
|
|
@interface XPMineUserInfoDesViewController ()<UITextViewDelegate>
|
|
///容器
|
|
@property (nonatomic, strong) UIView *containView;
|
|
///输入框
|
|
@property (nonatomic, strong) SZTextView *useDescTextView;
|
|
///清除按钮
|
|
@property (nonatomic, strong) UIButton *clearBtn;
|
|
///完成按钮
|
|
@property (nonatomic, strong) UIButton *completionBtn;
|
|
///显示输入的个数
|
|
@property (nonatomic, strong) UILabel *limitLabel;//
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPMineUserInfoDesViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.title = YMLocalizedString(@"XPMineUserInfoDesViewController0");
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self initEvents];
|
|
|
|
}
|
|
|
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
[self.view endEditing:YES];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
UIBarButtonItem *completeItem = [[UIBarButtonItem alloc] initWithCustomView:self.completionBtn];
|
|
self.navigationItem.rightBarButtonItem = completeItem;
|
|
[self.view addSubview:self.containView];
|
|
[self.containView addSubview:self.useDescTextView];
|
|
[self.containView addSubview:self.clearBtn];
|
|
[self.view addSubview:self.limitLabel];
|
|
self.useDescTextView.text = self.userDesc;
|
|
self.limitLabel.text = [NSString stringWithFormat:@"%ld",(maxCount - self.userDesc.length)];
|
|
self.limitLabel.textColor = self.userDesc.length > 0 ? [DJDKMIMOMColor mainTextColor] : [DJDKMIMOMColor secondTextColor];
|
|
self.completionBtn.enabled = self.useDescTextView.text.length > 0;
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(20);
|
|
make.left.mas_equalTo(self.view).offset(15);
|
|
make.right.mas_equalTo(self.view).offset(-15);
|
|
make.height.mas_equalTo(137);
|
|
}];
|
|
[self.useDescTextView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.mas_equalTo(self.containView).offset(10);
|
|
make.bottom.mas_equalTo(self.containView).offset(-10);
|
|
make.right.mas_equalTo(self.clearBtn.mas_left).offset(-5);
|
|
}];
|
|
[self.clearBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.containView).offset(10);
|
|
make.right.mas_equalTo(self.containView).offset(-10);
|
|
}];
|
|
[self.limitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.containView.mas_bottom).offset(5);
|
|
make.right.mas_equalTo(self.containView);
|
|
}];
|
|
}
|
|
|
|
- (void)initEvents {
|
|
@weakify(self);
|
|
RAC(self.completionBtn, enabled) = [RACSignal combineLatest:@[self.useDescTextView.rac_textSignal] reduce:^id _Nonnull(NSString *text){
|
|
@strongify(self);
|
|
self.limitLabel.text = [NSString stringWithFormat:@"%ld",(maxCount - text.length)];
|
|
if (text.length > maxCount) {
|
|
[self showErrorToast:[NSString stringWithFormat:YMLocalizedString(@"XPMineUserInfoDesViewController1"), maxCount]];
|
|
}
|
|
return @(text.length > 0 && text.length <= maxCount);
|
|
}];
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)completionBtnAction:(UIButton *)sender {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineUserInfoDesViewController:updateUserDes:)]) {
|
|
[self.delegate xPMineUserInfoDesViewController:self updateUserDes:self.useDescTextView.text];
|
|
}
|
|
}
|
|
|
|
- (void)clearBtnAction:(UIButton *)sender {
|
|
self.useDescTextView.text = @"";
|
|
self.completionBtn.enabled = NO;
|
|
self.limitLabel.text = [NSString stringWithFormat:@"%ld",(maxCount - self.useDescTextView.text.length)];
|
|
}
|
|
|
|
#pragma mark - getter && setter
|
|
- (UIView *)containView {
|
|
if (!_containView) {
|
|
_containView = [[UIView alloc] init];
|
|
_containView.layer.cornerRadius = 5;
|
|
_containView.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
|
|
}
|
|
return _containView;
|
|
}
|
|
|
|
- (SZTextView *)useDescTextView {
|
|
if (!_useDescTextView) {
|
|
_useDescTextView = [[SZTextView alloc] init];
|
|
_useDescTextView.delegate = self;
|
|
_useDescTextView.placeholder = YMLocalizedString(@"XPMineUserInfoDesViewController2");
|
|
_useDescTextView.placeholderTextColor = [DJDKMIMOMColor secondTextColor];
|
|
_useDescTextView.font = [UIFont systemFontOfSize:14];
|
|
_useDescTextView.textColor = [DJDKMIMOMColor mainTextColor];
|
|
_useDescTextView.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
|
|
}
|
|
return _useDescTextView;
|
|
}
|
|
|
|
- (UIButton *)completionBtn {
|
|
if (!_completionBtn) {
|
|
_completionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_completionBtn setTitle:YMLocalizedString(@"XPMineUserInfoDesViewController3") forState:UIControlStateNormal];
|
|
[_completionBtn setFrame:CGRectMake(0, 0, 50, 30)];
|
|
[_completionBtn setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal];
|
|
[_completionBtn setTitleColor:[DJDKMIMOMColor disableButtonTextColor] forState:UIControlStateDisabled];
|
|
[_completionBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
|
|
[_completionBtn addTarget:self action:@selector(completionBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _completionBtn;
|
|
}
|
|
|
|
- (UILabel *)limitLabel {
|
|
if (!_limitLabel) {
|
|
_limitLabel = [[UILabel alloc] init];
|
|
_limitLabel.font = [UIFont systemFontOfSize:14];
|
|
_limitLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
|
_limitLabel.text = @"60";
|
|
}
|
|
return _limitLabel;
|
|
}
|
|
|
|
- (UIButton *)clearBtn {
|
|
if (!_clearBtn) {
|
|
_clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_clearBtn setImage:[UIImage imageNamed:@"mine_user_info_edit_clear"] forState:UIControlStateNormal];
|
|
[_clearBtn addTarget:self action:@selector(clearBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _clearBtn;
|
|
}
|
|
|
|
@end
|