SurfaceSearchView.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // SurfaceSearchView.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/20.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "SurfaceSearchView.h"
  9. @interface SurfaceSearchView ()
  10. @property (nonatomic, strong) UIView *bgView;
  11. @property (nonatomic, strong) UIButton *searchButton;
  12. @property (nonatomic, strong) UIView *lineView;
  13. @property (nonatomic, strong) TDButton *backButton;
  14. @property (nonatomic, strong) TDButton *menuButton;
  15. @property (nonatomic, strong) UIView *shulineV;
  16. @property (nonatomic, strong) UIButton *bookBtn;
  17. @end
  18. @implementation SurfaceSearchView
  19. #pragma mark - init
  20. - (instancetype)init
  21. {
  22. self = [super init];
  23. if (self) {
  24. [self addSubview:self.bgView];
  25. [self addSubview:self.searchButton];
  26. [self addSubview:self.shulineV];
  27. [self addSubview:self.bookBtn];
  28. }
  29. return self;
  30. }
  31. - (void)setBgViewColor:(UIColor *)color {
  32. _bgView.backgroundColor = color;
  33. }
  34. - (void)searchAction:(UIButton *)sender {
  35. if (self.buttonBlock) {
  36. self.buttonBlock();
  37. }
  38. }
  39. - (void)setPlaceHolderText:(NSString *)text {
  40. [_searchButton setTitle:text forState:(UIControlStateNormal)];
  41. }
  42. - (void)showLineView {
  43. [self addSubview:self.lineView];
  44. CGRect frame = self.frame;
  45. _lineView.frame = CGRectMake(0, frame.size.height - 1, kGXScreenWidth, 1);
  46. }
  47. - (void)setLeftBackType {
  48. _searchButton.frame = CGRectMake(43, 7, kGXScreenWidth-55-43, 30);
  49. [self addSubview:self.backButton];
  50. }
  51. - (void)setRightMenuType {
  52. _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-64, 30);
  53. [self addSubview:self.menuButton];
  54. }
  55. - (void)setMainType {
  56. CGSize imageSize = _searchButton.imageView.frame.size;
  57. CGFloat totalWidth = kGXScreenWidth-32;
  58. _searchButton.imageEdgeInsets = UIEdgeInsetsMake(0, totalWidth-imageSize.width-20, 0, 0);
  59. _searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0);
  60. [_searchButton setTitleColor:[UIColor hexStringToColor:@"CCCCCC"] forState:(UIControlStateNormal)];
  61. }
  62. - (void)menuButtonAction:(TDButton *)sender {
  63. if ([self.delegate respondsToSelector:@selector(searchViewMenuAction)]) {
  64. [self.delegate searchViewMenuAction];
  65. }
  66. }
  67. - (void)backButtonAction:(TDButton *)sender {
  68. if ([self.delegate respondsToSelector:@selector(searchViewBackAction)]) {
  69. [self.delegate searchViewBackAction];
  70. return;
  71. }
  72. [[self viewController].navigationController popViewControllerAnimated:YES];
  73. }
  74. - (void)bookButtonAction:(UIButton *)sender
  75. {
  76. if (self.bookBlock) {
  77. self.bookBlock();
  78. }
  79. }
  80. #pragma mark - setter
  81. - (UIView *)bgView {
  82. if (!_bgView) {
  83. _bgView = [UIView new];
  84. _bgView.backgroundColor = [UIColor whiteColor];
  85. _bgView.frame = CGRectMake(0, 0, kGXScreenWidth, 52.f);
  86. }
  87. return _bgView;
  88. }
  89. - (UIButton *)searchButton {
  90. if (!_searchButton) {
  91. _searchButton = [UIButton new];
  92. _searchButton.backgroundColor = [UIColor whiteColor];
  93. _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-32, 38);
  94. NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] init];
  95. NSTextAttachment *attach = [[NSTextAttachment alloc] init];
  96. attach.image = [UIImage imageNamed:@"home_sousuo"];
  97. attach.bounds = CGRectMake(0, -2, 12, 13);
  98. NSAttributedString *collegeStr = [NSAttributedString attributedStringWithAttachment:attach];
  99. [attStr appendAttributedString:collegeStr];
  100. NSAttributedString *placeStr = [[NSAttributedString alloc] initWithString:@" 输入关键字搜索" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:UIColorHex(0xCCCCCC)}];
  101. [attStr appendAttributedString:placeStr];
  102. [_searchButton setAttributedTitle:attStr forState:UIControlStateNormal];
  103. _searchButton.layer.cornerRadius = 8.f;
  104. _searchButton.layer.borderWidth = 1.0f;
  105. _searchButton.layer.borderColor = [UIColor whiteColor].CGColor;
  106. _searchButton.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, -10);
  107. _searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  108. [_searchButton addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
  109. }
  110. return _searchButton;
  111. }
  112. - (UIView *)lineView {
  113. if (!_lineView) {
  114. _lineView = [UIView new];
  115. _lineView.backgroundColor = UIColorHex(E5E5E5);
  116. }
  117. return _lineView;
  118. }
  119. - (UIView *)shulineV {
  120. if (!_shulineV) {
  121. _shulineV = [UIView new];
  122. _shulineV.frame = CGRectMake(kGXScreenWidth - 16 - 49.5, 16.5, 0.5, 20);
  123. _shulineV.backgroundColor = UIColorHex(E5E5E5);
  124. }
  125. return _shulineV;
  126. }
  127. - (UIButton *)bookBtn {
  128. if (!_bookBtn) {
  129. _bookBtn = [UIButton new];
  130. _bookBtn.frame = CGRectMake(kGXScreenWidth - 16 - 49, 7, 49, 38);
  131. [_bookBtn setAttributedTitle:[[NSAttributedString alloc] initWithString:@"书城" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:UIColorHex(0x222222)}] forState:UIControlStateNormal];
  132. [_bookBtn addTarget:self action:@selector(bookButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  133. }
  134. return _bookBtn;
  135. }
  136. - (TDButton *)backButton {
  137. if (!_backButton) {
  138. _backButton = [[TDButton alloc] init];
  139. _backButton.frame = CGRectMake(22, 14, 8, 15);
  140. [_backButton setCurrentButtonHotSize:CGSizeZero];
  141. [_backButton setImage:IMG(@"icon_back_black") forState:UIControlStateNormal];
  142. [_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  143. }
  144. return _backButton;
  145. }
  146. - (TDButton *)menuButton {
  147. if (!_menuButton) {
  148. _menuButton = [[TDButton alloc] init];
  149. _menuButton.frame = CGRectMake(kGXScreenWidth-32, 14, 17, 15);
  150. [_menuButton setImage:IMG(@"icon_menu") forState:UIControlStateNormal];
  151. [_menuButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  152. }
  153. return _menuButton;
  154. }
  155. @end