| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //
- // HJSearchHotView.m
- // HappyJob
- //
- // Created by Bob on 2019/3/19.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "HJSearchHotView.h"
- #import "FBFlowLayoutView.h"
- #import "UIButton+HJTagButton.h"
- @interface HJSearchHotView () <FBFlowLayoutDelegate, FBFlowLayoutDataSource>
- @property (nonatomic, strong) UILabel *hotLabel;
- @property (nonatomic, strong) FBFlowLayoutView *hotView;
- @end
- @implementation HJSearchHotView
- #pragma mark - life cycle
- - (instancetype)init {
-
- if (self = [super init])
- {
- _hotTagArray = @[@"入职奖励", @"兼职日结", @"索尼", @"产线班长", @"有厂车", @"夏普", @"三星"];
- [self makeConstraints];
- }
- return self;
- }
- - (void)makeConstraints {
-
- [self addSubview:self.hotLabel];
- [self addSubview:self.hotView];
-
- [self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self);
- make.left.equalTo(self).with.offset(15);
- make.size.mas_equalTo(CGSizeMake(100, 20));
- }];
- [self.hotView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self);
- make.top.equalTo(self.hotLabel.mas_bottom).with.offset(0);
- }];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.hotView.mas_bottom).with.offset(0);
- }];
- }
- #pragma mark - FBFlowLayoutDelegate
- - (CGFloat)estimateWidthInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
-
- return SCREEN_WIDTH;
- }
- - (NSUInteger)numberInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
-
- return self.hotTagArray.count;
- }
- - (UIView *)flowLayoutView:(FBFlowLayoutView *)flowLayoutView subviewAtIndex:(NSUInteger)index {
-
- NSString *title = self.hotTagArray[index];
- CGSize maxSize = CGSizeMake(flowLayoutView.contentWidth, MAXFLOAT);
- UIButton *tagButton = [UIButton hj_createTagButtonWithTitle:title maxSize:maxSize];
- [tagButton setTitleColor:COLOR_666666 forState:UIControlStateNormal];
- return tagButton;
- }
- - (void)flowLayoutView:(FBFlowLayoutView *)flowLayoutView didSelectSubviewAtIndex:(NSUInteger)index {
-
- NSString *text = self.hotTagArray[index];
- if ([self.delegate respondsToSelector:@selector(searchHotView:didSelectText:)])
- {
- [self.delegate searchHotView:self didSelectText:text];
- }
- }
- #pragma mark - lazy
- - (UILabel *)hotLabel {
-
- if (_hotLabel == nil)
- {
- _hotLabel = [[UILabel alloc] init];
- _hotLabel.textColor = COLOR_000000;
- _hotLabel.text = @"热门搜索:";
- _hotLabel.font = [UIFont boldSystemFontOfSize:14];
- }
- return _hotLabel;
- }
- - (FBFlowLayoutView *)hotView {
-
- if (_hotView == nil)
- {
- _hotView = [[FBFlowLayoutView alloc] init];
- _hotView.numberOfLines = 0;
- _hotView.delegate = self;
- _hotView.dataSource = self;
- _hotView.edgeInsets = UIEdgeInsetsMake(10, 15, 10, 15);
- }
- return _hotView;
- }
- @end
|