HJSearchHotView.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // HJSearchHotView.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/3/19.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJSearchHotView.h"
  9. #import "FBFlowLayoutView.h"
  10. #import "UIButton+HJTagButton.h"
  11. @interface HJSearchHotView () <FBFlowLayoutDelegate, FBFlowLayoutDataSource>
  12. @property (nonatomic, strong) UILabel *hotLabel;
  13. @property (nonatomic, strong) FBFlowLayoutView *hotView;
  14. @end
  15. @implementation HJSearchHotView
  16. #pragma mark - life cycle
  17. - (instancetype)init {
  18. if (self = [super init])
  19. {
  20. _hotTagArray = @[@"入职奖励", @"兼职日结", @"索尼", @"产线班长", @"有厂车", @"夏普", @"三星"];
  21. [self makeConstraints];
  22. }
  23. return self;
  24. }
  25. - (void)makeConstraints {
  26. [self addSubview:self.hotLabel];
  27. [self addSubview:self.hotView];
  28. [self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.equalTo(self);
  30. make.left.equalTo(self).with.offset(15);
  31. make.size.mas_equalTo(CGSizeMake(100, 20));
  32. }];
  33. [self.hotView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.right.equalTo(self);
  35. make.top.equalTo(self.hotLabel.mas_bottom).with.offset(0);
  36. }];
  37. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.bottom.equalTo(self.hotView.mas_bottom).with.offset(0);
  39. }];
  40. }
  41. #pragma mark - FBFlowLayoutDelegate
  42. - (CGFloat)estimateWidthInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  43. return SCREEN_WIDTH;
  44. }
  45. - (NSUInteger)numberInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  46. return self.hotTagArray.count;
  47. }
  48. - (UIView *)flowLayoutView:(FBFlowLayoutView *)flowLayoutView subviewAtIndex:(NSUInteger)index {
  49. NSString *title = self.hotTagArray[index];
  50. CGSize maxSize = CGSizeMake(flowLayoutView.contentWidth, MAXFLOAT);
  51. UIButton *tagButton = [UIButton hj_createTagButtonWithTitle:title maxSize:maxSize];
  52. [tagButton setTitleColor:COLOR_666666 forState:UIControlStateNormal];
  53. return tagButton;
  54. }
  55. - (void)flowLayoutView:(FBFlowLayoutView *)flowLayoutView didSelectSubviewAtIndex:(NSUInteger)index {
  56. NSString *text = self.hotTagArray[index];
  57. if ([self.delegate respondsToSelector:@selector(searchHotView:didSelectText:)])
  58. {
  59. [self.delegate searchHotView:self didSelectText:text];
  60. }
  61. }
  62. #pragma mark - lazy
  63. - (UILabel *)hotLabel {
  64. if (_hotLabel == nil)
  65. {
  66. _hotLabel = [[UILabel alloc] init];
  67. _hotLabel.textColor = COLOR_000000;
  68. _hotLabel.text = @"热门搜索:";
  69. _hotLabel.font = [UIFont boldSystemFontOfSize:14];
  70. }
  71. return _hotLabel;
  72. }
  73. - (FBFlowLayoutView *)hotView {
  74. if (_hotView == nil)
  75. {
  76. _hotView = [[FBFlowLayoutView alloc] init];
  77. _hotView.numberOfLines = 0;
  78. _hotView.delegate = self;
  79. _hotView.dataSource = self;
  80. _hotView.edgeInsets = UIEdgeInsetsMake(10, 15, 10, 15);
  81. }
  82. return _hotView;
  83. }
  84. @end