SurfaceSearchView.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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) TDButton *searchButton;
  12. @property (nonatomic, strong) UIView *lineView;
  13. @property (nonatomic, strong) TDButton *backButton;
  14. @property (nonatomic, strong) TDButton *menuButton;
  15. @end
  16. @implementation SurfaceSearchView
  17. #pragma mark - init
  18. - (instancetype)init
  19. {
  20. self = [super init];
  21. if (self) {
  22. [self addSubview:self.bgView];
  23. [self addSubview:self.searchButton];
  24. }
  25. return self;
  26. }
  27. - (void)setBgViewColor:(UIColor *)color {
  28. _bgView.backgroundColor = color;
  29. }
  30. - (void)searchAction:(UIButton *)sender {
  31. if (self.buttonBlock) {
  32. self.buttonBlock();
  33. }
  34. }
  35. - (void)setPlaceHolderText:(NSString *)text {
  36. [_searchButton setTitle:text forState:(UIControlStateNormal)];
  37. }
  38. - (void)showLineView {
  39. [self addSubview:self.lineView];
  40. CGRect frame = self.frame;
  41. _lineView.frame = CGRectMake(0, frame.size.height - 1, kGXScreenWidth, 1);
  42. }
  43. - (void)setLeftBackType {
  44. _searchButton.frame = CGRectMake(43, 7, kGXScreenWidth-55-43, 30);
  45. [self addSubview:self.backButton];
  46. }
  47. - (void)setRightMenuType {
  48. _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-64, 30);
  49. [self addSubview:self.menuButton];
  50. }
  51. - (void)setMainType {
  52. CGSize imageSize = _searchButton.imageView.frame.size;
  53. CGFloat totalWidth = kGXScreenWidth-32;
  54. _searchButton.imageEdgeInsets = UIEdgeInsetsMake(0, totalWidth-imageSize.width-20, 0, 0);
  55. _searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0);
  56. [_searchButton setTitleColor:[UIColor hexStringToColor:@"CCCCCC"] forState:(UIControlStateNormal)];
  57. }
  58. - (void)menuButtonAction:(TDButton *)sender {
  59. if ([self.delegate respondsToSelector:@selector(searchViewMenuAction)]) {
  60. [self.delegate searchViewMenuAction];
  61. }
  62. }
  63. - (void)backButtonAction:(TDButton *)sender {
  64. if ([self.delegate respondsToSelector:@selector(searchViewBackAction)]) {
  65. [self.delegate searchViewBackAction];
  66. return;
  67. }
  68. [[self viewController].navigationController popViewControllerAnimated:YES];
  69. }
  70. #pragma mark - setter
  71. - (UIView *)bgView {
  72. if (!_bgView) {
  73. _bgView = [UIView new];
  74. _bgView.backgroundColor = [UIColor whiteColor];
  75. _bgView.frame = CGRectMake(0, 0, kGXScreenWidth, 52.f);
  76. }
  77. return _bgView;
  78. }
  79. - (UIButton *)searchButton {
  80. if (!_searchButton) {
  81. _searchButton = [TDButton buttonWithType:UIButtonTypeCustom];
  82. _searchButton.backgroundColor = [UIColor whiteColor];
  83. _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-32, 38);
  84. [_searchButton setImage:[UIImage imageNamed:@"searchIcon"] forState:(UIControlStateNormal)];
  85. [_searchButton setTitleColor:[UIColor hexStringToColor:@"999999"] forState:(UIControlStateNormal)];
  86. [_searchButton setTitle:@"搜索" forState:(UIControlStateNormal)];
  87. _searchButton.layer.cornerRadius = 8.f;
  88. _searchButton.layer.borderWidth = 1.0f;
  89. _searchButton.layer.borderColor = [UIColor whiteColor].CGColor;
  90. // [UIColor hexStringToColor:@"d8d8d8"].CGColor;
  91. [_searchButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
  92. _searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  93. _searchButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10);
  94. [_searchButton addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
  95. }
  96. return _searchButton;
  97. }
  98. - (UIView *)lineView {
  99. if (!_lineView) {
  100. _lineView = [UIView new];
  101. _lineView.backgroundColor = UIColorHex(E6E6E6);
  102. }
  103. return _lineView;
  104. }
  105. - (TDButton *)backButton {
  106. if (!_backButton) {
  107. _backButton = [[TDButton alloc] init];
  108. _backButton.frame = CGRectMake(22, 14, 8, 15);
  109. [_backButton setCurrentButtonHotSize:CGSizeZero];
  110. [_backButton setImage:IMG(@"icon_back_black") forState:UIControlStateNormal];
  111. [_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  112. }
  113. return _backButton;
  114. }
  115. - (TDButton *)menuButton {
  116. if (!_menuButton) {
  117. _menuButton = [[TDButton alloc] init];
  118. _menuButton.frame = CGRectMake(kGXScreenWidth-32, 14, 17, 15);
  119. [_menuButton setImage:IMG(@"icon_menu") forState:UIControlStateNormal];
  120. [_menuButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  121. }
  122. return _menuButton;
  123. }
  124. @end