// // YMSearchUserSearchInputBoxView.m // MSYOUPAI // // Created by YoMi on 2024/3/18. // Copyright © 2024 MS. All rights reserved. // #import "YMSearchUserSearchInputBoxView.h" #import "YMSearchUserViewModel.h" @interface YMSearchUserSearchInputBoxView () /// 搜索用户VM/ @property (nonatomic, strong) YMSearchUserViewModel *viewModel; /// 返回按钮 @property (nonatomic, strong) UIButton *backBtn; /// 搜索视图 @property (nonatomic, strong) UIView *searchView; /// 搜索图标 @property (nonatomic, strong) UIImageView *searchIcon; /// 搜索输入框 @property (nonatomic, strong) UITextField *searchInputBox; /// 搜索按钮 @property (nonatomic, strong) UIButton *searchBtn; @end @implementation YMSearchUserSearchInputBoxView - (void)ym_setupViews{ [self addSubview:self.backBtn]; [self addSubview:self.searchView]; [self.searchView addSubview:self.searchIcon]; [self.searchView addSubview:self.searchInputBox]; [self.searchView addSubview:self.searchBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints { [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.searchView.mas_centerY); make.left.equalTo(self).offset(adapt(15)); make.width.height.mas_equalTo(44); }]; [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(kYMStatusBarHeight + adapt(10)); make.left.equalTo(self.backBtn.mas_right).offset(adapt(10)); make.right.equalTo(self).offset(adapt(-15)); make.bottom.equalTo(self).offset(adapt(-10)); }]; [self.searchIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.searchView.mas_centerY); make.left.equalTo(self.searchView).offset(adapt(5)); make.width.height.mas_equalTo(adapt(18)); }]; [self.searchInputBox mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.searchView); make.left.equalTo(self.searchIcon.mas_right).offset(adapt(5)); make.bottom.equalTo(self.searchView); make.height.mas_equalTo(adapt(35)); }]; [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.searchView.mas_centerY); make.left.equalTo(self.searchInputBox.mas_right).offset(adapt(10)); make.right.equalTo(self.searchView).offset(adapt(-5)); make.width.mas_equalTo(adapt(60)); make.height.mas_equalTo(adapt(30)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMSearchUserViewModel*)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; } - (UIButton *)backBtn{ if (!_backBtn) { _backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_backBtn setImage:ImageByName(@"ym_navigation_black_icon") forState:UIControlStateNormal]; [[[_backBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES]; }]; /** *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸) */ [_backBtn setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; /** *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩) **/ [_backBtn setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; } return _backBtn; } - (UIView *)searchView{ if (!_searchView) { _searchView = [[UIView alloc]init]; _searchView.backgroundColor = HexColorFromRGB(0xF6F6F6); _searchView.layer.cornerRadius = adapt(10); } return _searchView; } - (UIImageView *)searchIcon{ if (!_searchIcon) { _searchIcon = [[UIImageView alloc]init]; _searchIcon.image = ImageByName(@"ym_search_user_search_icon"); } return _searchIcon; } - (UITextField *)searchInputBox{ if (!_searchInputBox) { NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入相语欢颜号"]; placeholderAttributed.yy_paragraphStyle = style; placeholderAttributed.yy_font = LCFont(14); placeholderAttributed.yy_color = HexColorFromRGB(0x98989a); _searchInputBox = [[UITextField alloc]init]; _searchInputBox.attributedPlaceholder = placeholderAttributed; _searchInputBox.clearButtonMode = UITextFieldViewModeWhileEditing; _searchInputBox.autocorrectionType = UITextAutocorrectionTypeDefault; _searchInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone; _searchInputBox.keyboardType = UIKeyboardTypeDefault; WS(weakSelf) [[[_searchInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id value) { weakSelf.viewModel.searchKeywords = value; }]; /** *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸) */ [_searchInputBox setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal]; /** *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩) **/ [_searchInputBox setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal]; } return _searchInputBox; } - (UIButton *)searchBtn{ if (!_searchBtn) { _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _searchBtn.titleLabel.font = LCFont(14); [_searchBtn setTitle:@"搜索" forState:UIControlStateNormal]; [_searchBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; [_searchBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; _searchBtn.layer.cornerRadius = adapt(8); _searchBtn.layer.masksToBounds = YES; /** *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸) */ [_searchBtn setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; /** *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩) **/ [_searchBtn setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; WS(weakSelf) [[[_searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel getSearchUserListData]; }]; } return _searchBtn; } @end