123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // InfoSearchView.m
- // TheoryNetwork
- //
- // Created by tederen on 2019/9/20.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "InfoSearchView.h"
- @interface InfoSearchView () <UISearchBarDelegate>
- @property (nonatomic, strong) TDButton *backButton;
- @property (nonatomic, strong) TDButton *cancelButton;
- @property (nonatomic, strong) UIView *lineView;
- @end
- @implementation InfoSearchView
- - (instancetype)initWithFrame:(CGRect)frame type:(InfoSearchViewType)type
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.backButton.frame = CGRectMake(16, (frame.size.height-14)/2.0, 7, 14);
- self.searchBar.frame = CGRectMake(16+7+16, 7, kGXScreenWidth-32-16-7, 30);
-
- [self addSubview:self.backButton];
- [self addSubview:self.searchBar];
-
- if (type == InfoSearchViewTypeCancel) {
- CGFloat rightMargin = 16.f;
-
- CGSize btnSize = [self.cancelButton sizeThatFits:CGSizeZero];
- self.cancelButton.frame = CGRectMake(kGXScreenWidth - rightMargin - btnSize.width, (frame.size.height-btnSize.height)/2.0, btnSize.width, btnSize.height);
- [self addSubview:self.cancelButton];
- rightMargin += btnSize.width + 16.f;
-
- self.searchBar.frame = CGRectMake(16+7+16, 7, kGXScreenWidth-32-7-rightMargin, 30);
- }
- // [self.searchBar becomeFirstResponder];
- }
- return self;
- }
- - (void)setNowSearchData:(NSString *)searchStr {
- _searchBar.text = searchStr;
- }
- - (void)showLineView {
- [self addSubview:self.lineView];
- CGRect frame = self.frame;
- _lineView.frame = CGRectMake(0, frame.size.height - 1, kGXScreenWidth, 0.5);
- }
- - (void)backAction:(TDButton *)sender {
- if (self.backBlock) {
- self.backBlock();
- }
- }
- - (void)cancelAction:(TDButton *)sender {
- if (self.cancelBlock) {
- self.cancelBlock();
- }
- }
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
- if ([self.delegate respondsToSelector:@selector(textDidChange:)]) {
- [self.delegate textDidChange:searchText];
- }
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
- if ([self.delegate respondsToSelector:@selector(searchButtonAction:)]) {
- [self.delegate searchButtonAction:searchBar];
- }
- }
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
- self.searchBar.placeholder = @"";
- return YES;
- }
- - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
- if (self.searchPlaceholder.length > 0) {
- self.searchBar.placeholder = self.searchPlaceholder;
- }else{
- self.searchBar.placeholder = @" 搜索";
- }
- return YES;
- }
- #pragma mark - setter
- - (TDButton *)backButton {
- if (!_backButton) {
- _backButton = [TDButton buttonWithType:UIButtonTypeCustom];
- [_backButton setCurrentButtonHotSize:CGSizeZero];
- [_backButton setImage:IMG(@"首页-书籍详情-返回") forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- - (TDSearchBar *)searchBar {
- if (!_searchBar) {
- _searchBar = [[TDSearchBar alloc] init];
- // _searchBar.placeholder = @" 搜索";
- _searchBar.delegate = self;
- }
- return _searchBar;
- }
- - (TDButton *)cancelButton {
- if (!_cancelButton) {
- _cancelButton = [TDButton buttonWithType:UIButtonTypeCustom];
- [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
- [_cancelButton setTitleColor:UIColorHex(1682DA) forState:UIControlStateNormal];
- [[_cancelButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
- [_cancelButton setCurrentButtonHotSize:CGSizeZero];
- [_cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _cancelButton;
- }
- - (UIView *)lineView {
- if (!_lineView) {
- _lineView = [UIView new];
- _lineView.backgroundColor = UIColorHex(CCCCCC);
- }
- return _lineView;
- }
- @end
|