// // SurfaceSearchView.m // TheoryNetwork // // Created by tederen on 2019/9/20. // Copyright © 2019 tederen. All rights reserved. // #import "SurfaceSearchView.h" @interface SurfaceSearchView () @property (nonatomic, strong) UIView *bgView; @property (nonatomic, strong) UIButton *searchButton; @property (nonatomic, strong) UIView *lineView; @property (nonatomic, strong) TDButton *backButton; @property (nonatomic, strong) TDButton *menuButton; @property (nonatomic, strong) UIView *shulineV; @property (nonatomic, strong) UIButton *bookBtn; @end @implementation SurfaceSearchView #pragma mark - init - (instancetype)init { self = [super init]; if (self) { [self addSubview:self.bgView]; [self addSubview:self.searchButton]; [self addSubview:self.shulineV]; [self addSubview:self.bookBtn]; } return self; } - (void)setBgViewColor:(UIColor *)color { _bgView.backgroundColor = color; } - (void)searchAction:(UIButton *)sender { if (self.buttonBlock) { self.buttonBlock(); } } - (void)setPlaceHolderText:(NSString *)text { [_searchButton setTitle:text forState:(UIControlStateNormal)]; } - (void)showLineView { [self addSubview:self.lineView]; CGRect frame = self.frame; _lineView.frame = CGRectMake(0, frame.size.height - 1, kGXScreenWidth, 1); } - (void)setLeftBackType { _searchButton.frame = CGRectMake(43, 7, kGXScreenWidth-55-43, 30); [self addSubview:self.backButton]; } - (void)setRightMenuType { _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-64, 30); [self addSubview:self.menuButton]; } - (void)setMainType { CGSize imageSize = _searchButton.imageView.frame.size; CGFloat totalWidth = kGXScreenWidth-32; _searchButton.imageEdgeInsets = UIEdgeInsetsMake(0, totalWidth-imageSize.width-20, 0, 0); _searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0); [_searchButton setTitleColor:[UIColor hexStringToColor:@"CCCCCC"] forState:(UIControlStateNormal)]; } - (void)menuButtonAction:(TDButton *)sender { if ([self.delegate respondsToSelector:@selector(searchViewMenuAction)]) { [self.delegate searchViewMenuAction]; } } - (void)backButtonAction:(TDButton *)sender { if ([self.delegate respondsToSelector:@selector(searchViewBackAction)]) { [self.delegate searchViewBackAction]; return; } [[self viewController].navigationController popViewControllerAnimated:YES]; } - (void)bookButtonAction:(UIButton *)sender { if (self.bookBlock) { self.bookBlock(); } } #pragma mark - setter - (UIView *)bgView { if (!_bgView) { _bgView = [UIView new]; _bgView.backgroundColor = [UIColor whiteColor]; _bgView.frame = CGRectMake(0, 0, kGXScreenWidth, 52.f); } return _bgView; } - (UIButton *)searchButton { if (!_searchButton) { _searchButton = [UIButton new]; _searchButton.backgroundColor = [UIColor whiteColor]; _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-32, 38); NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] init]; NSTextAttachment *attach = [[NSTextAttachment alloc] init]; attach.image = [UIImage imageNamed:@"home_sousuo"]; attach.bounds = CGRectMake(0, -2, 12, 13); NSAttributedString *collegeStr = [NSAttributedString attributedStringWithAttachment:attach]; [attStr appendAttributedString:collegeStr]; NSAttributedString *placeStr = [[NSAttributedString alloc] initWithString:@" 输入关键字搜索" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:UIColorHex(0xCCCCCC)}]; [attStr appendAttributedString:placeStr]; [_searchButton setAttributedTitle:attStr forState:UIControlStateNormal]; _searchButton.layer.cornerRadius = 8.f; _searchButton.layer.borderWidth = 1.0f; _searchButton.layer.borderColor = [UIColor whiteColor].CGColor; _searchButton.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, -10); _searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_searchButton addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside]; } return _searchButton; } - (UIView *)lineView { if (!_lineView) { _lineView = [UIView new]; _lineView.backgroundColor = UIColorHex(E5E5E5); } return _lineView; } - (UIView *)shulineV { if (!_shulineV) { _shulineV = [UIView new]; _shulineV.frame = CGRectMake(kGXScreenWidth - 16 - 49.5, 16.5, 0.5, 20); _shulineV.backgroundColor = UIColorHex(E5E5E5); } return _shulineV; } - (UIButton *)bookBtn { if (!_bookBtn) { _bookBtn = [UIButton new]; _bookBtn.frame = CGRectMake(kGXScreenWidth - 16 - 49, 7, 49, 38); [_bookBtn setAttributedTitle:[[NSAttributedString alloc] initWithString:@"书城" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:UIColorHex(0x222222)}] forState:UIControlStateNormal]; [_bookBtn addTarget:self action:@selector(bookButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _bookBtn; } - (TDButton *)backButton { if (!_backButton) { _backButton = [[TDButton alloc] init]; _backButton.frame = CGRectMake(22, 14, 8, 15); [_backButton setCurrentButtonHotSize:CGSizeZero]; [_backButton setImage:IMG(@"icon_back_black") forState:UIControlStateNormal]; [_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _backButton; } - (TDButton *)menuButton { if (!_menuButton) { _menuButton = [[TDButton alloc] init]; _menuButton.frame = CGRectMake(kGXScreenWidth-32, 14, 17, 15); [_menuButton setImage:IMG(@"icon_menu") forState:UIControlStateNormal]; [_menuButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _menuButton; } @end