admin
2022-01-17 b63ed504f6d1e652d9fbd67c1490e7821b159c75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
//  RecommendNavView.m
//  BuWanVideo2.0
//
//  Created by Aeline on 2021/5/23.
//  Copyright © 2021 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "RecommendNavView.h"
 
@interface RecommendNavView ()
 
@property (nonatomic, strong) UIView *viewNav;
@property (nonatomic, strong) UIView *viewSearch;
 
@end
 
@implementation RecommendNavView
 
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewConfig];
    }
    return self;
}
 
- (void)setupViewConfig {
    [self addSubview:self.viewNav];
    self.viewNav.sd_layout.topSpaceToView(self, kStatusBarH).leftEqualToView(self).rightEqualToView(self).heightIs(44);
    
    //UIButton *buttonMore = [[UIButton alloc] init];
    //[buttonMore setImage:[UIImage imageNamed:@"home_more"] forState:UIControlStateNormal];
    //[self addSubview:buttonMore];
    //buttonMore.sd_layout.rightSpaceToView(self, 18).centerYEqualToView(_viewNav).widthIs(21).heightIs(24);
    
    UIButton *buttonRecord = [[UIButton alloc] init];
    [buttonRecord setImage:[UIImage imageNamed:@"home_record"] forState:UIControlStateNormal];
    [self addSubview:buttonRecord];
    buttonRecord.sd_layout.rightSpaceToView(self, 51).centerYEqualToView(_viewNav).widthIs(23).heightIs(23);
    [buttonRecord addTarget:self action:@selector(onViewRecord) forControlEvents:UIControlEventTouchUpInside];
    
    //分类
    UIButton *buttonCategory = [[UIButton alloc] init];
    [buttonCategory setImage:[UIImage imageNamed:@"home_category"] forState:UIControlStateNormal];
    [self addSubview:buttonCategory];
    buttonCategory.sd_layout.rightSpaceToView(self, 10).centerYEqualToView(buttonRecord).widthIs(23).heightIs(23);
    [buttonCategory addTarget:self action:@selector(onViewCategory) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [self.viewNav addSubview:self.viewSearch];
    self.viewSearch.sd_layout.leftSpaceToView(self.viewNav, 11).centerYEqualToView(self.viewNav).rightSpaceToView(buttonRecord, 21).heightIs(34);
    self.viewSearch.sd_cornerRadius = @17;
    
    UIImageView *imageViewSearch = [[UIImageView alloc] init];
    imageViewSearch.image = [UIImage imageNamed:@"home_search"];
    [_viewSearch addSubview:imageViewSearch];
    imageViewSearch.sd_layout.leftSpaceToView(_viewSearch, 13).centerYEqualToView(_viewSearch).widthIs(19).heightIs(19);
    
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:14];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = UICOLOR_FROM_RGB(0x787878, 1);
    [_viewSearch addSubview:label];
    label.sd_layout.leftSpaceToView(imageViewSearch, 13).centerYEqualToView(_viewSearch).heightIs(20).rightSpaceToView(_viewSearch, 0);
}
 
- (void)onViewRecord {
    !self.onRecord?:self.onRecord();
}
 
- (void)onViewCategory {
    !self.onCategory?:self.onCategory();
}
 
- (void)touchSearch {
    !self.onSearch?:self.onSearch();
}
 
- (void)setTitle:(NSString *)title {
    _title = title;
    if (title) {
        UILabel *label = [self.viewSearch subviews][1];
        label.text = title;
    }
}
 
- (UIView *)viewNav {
    if (!_viewNav) {
        _viewNav = [[UIView alloc] init];
    }
    return _viewNav;
}
 
- (UIView *)viewSearch {
    if (!_viewSearch) {
        _viewSearch = [[UIView alloc] init];
        _viewSearch.backgroundColor = UICOLOR_FROM_RGB(0xEBEBEB, 1);
        _viewSearch.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchSearch)];
        [_viewSearch addGestureRecognizer:tap];
    }
    return _viewSearch;
}
@end