123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // 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 *menuButton;
- @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(0, 0, 50,44);
- self.menuButton.frame = CGRectMake(50, 0, 35,44);
- self.searchBar.frame = CGRectMake(90, 4, kGXScreenWidth - 105, 36);
- self.menuButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [self addSubview:self.backButton];
- [self addSubview:self.menuButton];
- [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)menuAction:(TDButton *)sender {
- if (self.menuBlock) {
- self.menuBlock();
- }
- }
- - (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 setCusPlaceholder:@""];
- return YES;
- }
- - (void)setBarPlaceholder:(NSString *)searchPlaceholder
- {
- [self.searchBar setCusPlaceholder:searchPlaceholder];
- // self.searchBar.placeholder = searchPlaceholder;
- self.searchPlaceholder = searchPlaceholder;
- }
- - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
- if (self.searchPlaceholder.length > 0) {
- [self.searchBar setCusPlaceholder:self.searchPlaceholder];
- }else{
- [self.searchBar setCusPlaceholder:@" 搜索"];
- }
- return YES;
- }
- #pragma mark - setter
- - (TDButton *)backButton {
- if (!_backButton) {
- _backButton = [TDButton buttonWithType:UIButtonTypeCustom];
- [_backButton setCurrentButtonHotSize:CGSizeZero];
- [_backButton setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- - (TDButton *)menuButton {
- if (!_menuButton) {
- _menuButton = [TDButton buttonWithType:UIButtonTypeCustom];
- [_menuButton setCurrentButtonHotSize:CGSizeZero];
- [_menuButton setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal];
- [_menuButton addTarget:self action:@selector(menuAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _menuButton;
- }
- - (TDSearchBar *)searchBar {
- if (!_searchBar) {
- _searchBar = [[TDSearchBar alloc] initWithFrame:CGRectZero];
- // _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.hidden = YES;
- _lineView.backgroundColor = UIColorHex(CCCCCC);
- }
- return _lineView;
- }
- @end
|