YMSearchUserSearchInputBoxView.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // YMSearchUserSearchInputBoxView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/18.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMSearchUserSearchInputBoxView.h"
  9. #import "YMSearchUserViewModel.h"
  10. @interface YMSearchUserSearchInputBoxView ()
  11. /// 搜索用户VM/
  12. @property (nonatomic, strong) YMSearchUserViewModel *viewModel;
  13. /// 返回按钮
  14. @property (nonatomic, strong) UIButton *backBtn;
  15. /// 搜索视图
  16. @property (nonatomic, strong) UIView *searchView;
  17. /// 搜索图标
  18. @property (nonatomic, strong) UIImageView *searchIcon;
  19. /// 搜索输入框
  20. @property (nonatomic, strong) UITextField *searchInputBox;
  21. /// 搜索按钮
  22. @property (nonatomic, strong) UIButton *searchBtn;
  23. @end
  24. @implementation YMSearchUserSearchInputBoxView
  25. - (void)ym_setupViews{
  26. [self addSubview:self.backBtn];
  27. [self addSubview:self.searchView];
  28. [self.searchView addSubview:self.searchIcon];
  29. [self.searchView addSubview:self.searchInputBox];
  30. [self.searchView addSubview:self.searchBtn];
  31. [self setNeedsUpdateConstraints];
  32. [self updateConstraintsIfNeeded];
  33. }
  34. - (void)updateConstraints {
  35. [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.centerY.equalTo(self.searchView.mas_centerY);
  37. make.left.equalTo(self).offset(adapt(15));
  38. make.width.height.mas_equalTo(44);
  39. }];
  40. [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.equalTo(self).offset(kYMStatusBarHeight + adapt(10));
  42. make.left.equalTo(self.backBtn.mas_right).offset(adapt(10));
  43. make.right.equalTo(self).offset(adapt(-15));
  44. make.bottom.equalTo(self).offset(adapt(-10));
  45. }];
  46. [self.searchIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerY.equalTo(self.searchView.mas_centerY);
  48. make.left.equalTo(self.searchView).offset(adapt(5));
  49. make.width.height.mas_equalTo(adapt(18));
  50. }];
  51. [self.searchInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.top.equalTo(self.searchView);
  53. make.left.equalTo(self.searchIcon.mas_right).offset(adapt(5));
  54. make.bottom.equalTo(self.searchView);
  55. make.height.mas_equalTo(adapt(35));
  56. }];
  57. [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.centerY.equalTo(self.searchView.mas_centerY);
  59. make.left.equalTo(self.searchInputBox.mas_right).offset(adapt(10));
  60. make.right.equalTo(self.searchView).offset(adapt(-5));
  61. make.width.mas_equalTo(adapt(60));
  62. make.height.mas_equalTo(adapt(30));
  63. }];
  64. [super updateConstraints];
  65. }
  66. - (void)ym_bindViewModel:(YMSearchUserViewModel*)viewModel{
  67. if (!viewModel) {
  68. return;
  69. }
  70. _viewModel = viewModel;
  71. }
  72. - (UIButton *)backBtn{
  73. if (!_backBtn) {
  74. _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  75. [_backBtn setImage:ImageByName(@"ym_navigation_black_icon") forState:UIControlStateNormal];
  76. [[[_backBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  77. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  78. }];
  79. /**
  80. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  81. */
  82. [_backBtn setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  83. /**
  84. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  85. **/
  86. [_backBtn setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  87. }
  88. return _backBtn;
  89. }
  90. - (UIView *)searchView{
  91. if (!_searchView) {
  92. _searchView = [[UIView alloc]init];
  93. _searchView.backgroundColor = HexColorFromRGB(0xF6F6F6);
  94. _searchView.layer.cornerRadius = adapt(10);
  95. }
  96. return _searchView;
  97. }
  98. - (UIImageView *)searchIcon{
  99. if (!_searchIcon) {
  100. _searchIcon = [[UIImageView alloc]init];
  101. _searchIcon.image = ImageByName(@"ym_search_user_search_icon");
  102. }
  103. return _searchIcon;
  104. }
  105. - (UITextField *)searchInputBox{
  106. if (!_searchInputBox) {
  107. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  108. style.minimumLineHeight = 0;
  109. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入相语欢颜号"];
  110. placeholderAttributed.yy_paragraphStyle = style;
  111. placeholderAttributed.yy_font = LCFont(14);
  112. placeholderAttributed.yy_color = HexColorFromRGB(0x98989a);
  113. _searchInputBox = [[UITextField alloc]init];
  114. _searchInputBox.attributedPlaceholder = placeholderAttributed;
  115. _searchInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  116. _searchInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  117. _searchInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  118. _searchInputBox.keyboardType = UIKeyboardTypeDefault;
  119. WS(weakSelf)
  120. [[[_searchInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id value) {
  121. weakSelf.viewModel.searchKeywords = value;
  122. }];
  123. /**
  124. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  125. */
  126. [_searchInputBox setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  127. /**
  128. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  129. **/
  130. [_searchInputBox setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  131. }
  132. return _searchInputBox;
  133. }
  134. - (UIButton *)searchBtn{
  135. if (!_searchBtn) {
  136. _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  137. _searchBtn.titleLabel.font = LCFont(14);
  138. [_searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
  139. [_searchBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  140. [_searchBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  141. _searchBtn.layer.cornerRadius = adapt(8);
  142. _searchBtn.layer.masksToBounds = YES;
  143. /**
  144. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  145. */
  146. [_searchBtn setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  147. /**
  148. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  149. **/
  150. [_searchBtn setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  151. WS(weakSelf)
  152. [[[_searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  153. [weakSelf.viewModel getSearchUserListData];
  154. }];
  155. }
  156. return _searchBtn;
  157. }
  158. @end