123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // KBFindTopView.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/1/19.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBFindTopView.h"
- #import "KBCollectionView.h"
- #import "KBFindTopCollectionViewCell.h"
- static NSString *const cellID = @"KBFindTopCollectionViewCell";
- @interface KBFindTopView () <UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation KBFindTopView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor whiteColor];
-
- [self initSubviews];
- }
- return self;
- }
- - (void)initSubviews {
- UIImageView *iconImageView = [[UIImageView alloc] init];
- iconImageView.backgroundColor = [UIColor clearColor];
- iconImageView.image = [UIImage imageNamed:@"hot_search"];
- [self addSubview:iconImageView];
-
- UILabel *nameLabel = [[UILabel alloc] init];
- nameLabel.backgroundColor = [UIColor clearColor];
- nameLabel.text = @"正在热搜";
- nameLabel.textColor = [UIColor YHColorWithHex:0x222222];
- nameLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
- [self addSubview:nameLabel];
-
- [self addSubview:self.collectionView];
-
- [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(FITSIZE(15));
- make.centerY.equalTo(nameLabel);
- make.size.mas_equalTo(CGSizeMake(FITSIZE(12), FITSIZE(11)));
- }];
-
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(iconImageView.mas_right).offset(FITSIZE(8));
- make.top.equalTo(self).offset(FITSIZE(16));
- }];
-
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self);
- make.top.equalTo(self).offset(FITSIZE(44));
- make.size.mas_equalTo(CGSizeMake(kScreenWidth, FITSIZE(75)));
- }];
- }
- - (void)setDataSource:(NSMutableArray *)dataSource {
- _dataSource = dataSource;
- [self.collectionView reloadData];
- }
- #pragma mark - collectionView
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataSource.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- KBFindTopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
- KBFindHotSearchModel *model = self.dataSource[indexPath.item];
- cell.model = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if ([self.delegate respondsToSelector:@selector(yh_FindTopViewDidSelectItemAtIndexPath:)]) {
- [self.delegate yh_FindTopViewDidSelectItemAtIndexPath:indexPath];
- }
- }
- #pragma mark - lazy
- - (UICollectionView *)collectionView {
- if (!_collectionView) {
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- flowLayout.itemSize = CGSizeMake(FITSIZE(108), FITSIZE(75));
- flowLayout.minimumLineSpacing = FITSIZE(10);
- flowLayout.minimumInteritemSpacing = FITSIZE(10);
- flowLayout.sectionInset = UIEdgeInsetsMake(0, FITSIZE(15), 0, FITSIZE(15));
-
- _collectionView = [[KBCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- _collectionView.scrollEnabled = NO;
- _collectionView.bounces = NO;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- [_collectionView registerClass:[KBFindTopCollectionViewCell class] forCellWithReuseIdentifier:cellID];
- }
- return _collectionView;
- }
- @end
|