123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //
- // 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) TDButton *searchButton;
- @property (nonatomic, strong) UIView *lineView;
- @property (nonatomic, strong) TDButton *backButton;
- @property (nonatomic, strong) TDButton *menuButton;
- @end
- @implementation SurfaceSearchView
- #pragma mark - init
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- [self addSubview:self.bgView];
- [self addSubview:self.searchButton];
- }
- 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];
- }
- #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 = [TDButton buttonWithType:UIButtonTypeCustom];
- _searchButton.backgroundColor = [UIColor whiteColor];
- _searchButton.frame = CGRectMake(16, 7, kGXScreenWidth-32, 38);
- [_searchButton setImage:[UIImage imageNamed:@"searchIcon"] forState:(UIControlStateNormal)];
- [_searchButton setTitleColor:[UIColor hexStringToColor:@"999999"] forState:(UIControlStateNormal)];
- [_searchButton setTitle:@"搜索" forState:(UIControlStateNormal)];
- _searchButton.layer.cornerRadius = 8.f;
- _searchButton.layer.borderWidth = 1.0f;
- _searchButton.layer.borderColor = [UIColor whiteColor].CGColor;
- // [UIColor hexStringToColor:@"d8d8d8"].CGColor;
- [_searchButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
- _searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- _searchButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10);
- [_searchButton addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _searchButton;
- }
- - (UIView *)lineView {
- if (!_lineView) {
- _lineView = [UIView new];
- _lineView.backgroundColor = UIColorHex(E6E6E6);
- }
- return _lineView;
- }
- - (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
|