InfoSearchView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // InfoSearchView.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/20.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "InfoSearchView.h"
  9. @interface InfoSearchView () <UISearchBarDelegate>
  10. @property (nonatomic, strong) TDButton *backButton;
  11. @property (nonatomic, strong) TDButton *menuButton;
  12. @property (nonatomic, strong) TDButton *cancelButton;
  13. @property (nonatomic, strong) UIView *lineView;
  14. @end
  15. @implementation InfoSearchView
  16. - (instancetype)initWithFrame:(CGRect)frame type:(InfoSearchViewType)type
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.backButton.frame = CGRectMake(0, 0, 50,44);
  21. self.menuButton.frame = CGRectMake(50, 0, 35,44);
  22. self.searchBar.frame = CGRectMake(90, 4, kGXScreenWidth - 105, 36);
  23. self.menuButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  24. [self addSubview:self.backButton];
  25. [self addSubview:self.menuButton];
  26. [self addSubview:self.searchBar];
  27. // if (type == InfoSearchViewTypeCancel) {
  28. // CGFloat rightMargin = 16.f;
  29. //
  30. // CGSize btnSize = [self.cancelButton sizeThatFits:CGSizeZero];
  31. // self.cancelButton.frame = CGRectMake(kGXScreenWidth - rightMargin - btnSize.width, (frame.size.height-btnSize.height)/2.0, btnSize.width, btnSize.height);
  32. // [self addSubview:self.cancelButton];
  33. // rightMargin += btnSize.width + 16.f;
  34. //
  35. // self.searchBar.frame = CGRectMake(16+7+16, 7, kGXScreenWidth-32-7-rightMargin, 30);
  36. // }
  37. // [self.searchBar becomeFirstResponder];
  38. }
  39. return self;
  40. }
  41. - (void)setNowSearchData:(NSString *)searchStr {
  42. _searchBar.text = searchStr;
  43. }
  44. - (void)showLineView {
  45. [self addSubview:self.lineView];
  46. CGRect frame = self.frame;
  47. _lineView.frame = CGRectMake(0, frame.size.height - 1, kGXScreenWidth, 0.5);
  48. }
  49. - (void)backAction:(TDButton *)sender {
  50. if (self.backBlock) {
  51. self.backBlock();
  52. }
  53. }
  54. - (void)menuAction:(TDButton *)sender {
  55. if (self.menuBlock) {
  56. self.menuBlock();
  57. }
  58. }
  59. - (void)cancelAction:(TDButton *)sender {
  60. if (self.cancelBlock) {
  61. self.cancelBlock();
  62. }
  63. }
  64. //- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  65. // if ([self.delegate respondsToSelector:@selector(textDidChange:)]) {
  66. // [self.delegate textDidChange:searchText];
  67. // }
  68. //}
  69. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
  70. if ([self.delegate respondsToSelector:@selector(searchButtonAction:)]) {
  71. [self.delegate searchButtonAction:searchBar];
  72. }
  73. }
  74. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
  75. [self.searchBar setCusPlaceholder:@""];
  76. return YES;
  77. }
  78. - (void)setBarPlaceholder:(NSString *)searchPlaceholder
  79. {
  80. [self.searchBar setCusPlaceholder:searchPlaceholder];
  81. // self.searchBar.placeholder = searchPlaceholder;
  82. self.searchPlaceholder = searchPlaceholder;
  83. }
  84. - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
  85. if (self.searchPlaceholder.length > 0) {
  86. [self.searchBar setCusPlaceholder:self.searchPlaceholder];
  87. }else{
  88. [self.searchBar setCusPlaceholder:@" 搜索"];
  89. }
  90. return YES;
  91. }
  92. #pragma mark - setter
  93. - (TDButton *)backButton {
  94. if (!_backButton) {
  95. _backButton = [TDButton buttonWithType:UIButtonTypeCustom];
  96. [_backButton setCurrentButtonHotSize:CGSizeZero];
  97. [_backButton setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  98. [_backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
  99. }
  100. return _backButton;
  101. }
  102. - (TDButton *)menuButton {
  103. if (!_menuButton) {
  104. _menuButton = [TDButton buttonWithType:UIButtonTypeCustom];
  105. [_menuButton setCurrentButtonHotSize:CGSizeZero];
  106. [_menuButton setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal];
  107. [_menuButton addTarget:self action:@selector(menuAction:) forControlEvents:UIControlEventTouchUpInside];
  108. }
  109. return _menuButton;
  110. }
  111. - (TDSearchBar *)searchBar {
  112. if (!_searchBar) {
  113. _searchBar = [[TDSearchBar alloc] initWithFrame:CGRectZero];
  114. // _searchBar.placeholder = @" 搜索";
  115. _searchBar.delegate = self;
  116. }
  117. return _searchBar;
  118. }
  119. - (TDButton *)cancelButton {
  120. if (!_cancelButton) {
  121. _cancelButton = [TDButton buttonWithType:UIButtonTypeCustom];
  122. [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
  123. [_cancelButton setTitleColor:UIColorHex(1682DA) forState:UIControlStateNormal];
  124. [[_cancelButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
  125. [_cancelButton setCurrentButtonHotSize:CGSizeZero];
  126. [_cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
  127. }
  128. return _cancelButton;
  129. }
  130. - (UIView *)lineView {
  131. if (!_lineView) {
  132. _lineView = [UIView new];
  133. _lineView.hidden = YES;
  134. _lineView.backgroundColor = UIColorHex(CCCCCC);
  135. }
  136. return _lineView;
  137. }
  138. @end