PFBottomColletionView.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // PFBottomColletionView.m
  3. // SMEngineDemo
  4. //
  5. // Created by mumu on 2019/11/6.
  6. // Copyright © 2019 pfdetect. All rights reserved.
  7. //
  8. #import "PFBottomColletionView.h"
  9. #pragma mark - FUBottomBottomCell
  10. @implementation FUBottomBottomCell
  11. - (id)initWithFrame:(CGRect)frame{
  12. self = [super initWithFrame:frame];
  13. if (self){
  14. _botlabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 20)];
  15. _botlabel.textAlignment = NSTextAlignmentCenter;
  16. _botlabel.textColor = [UIColor colorWithRed:44/255.0 green:46/255.0 blue:48/255.0 alpha:1.0];
  17. _botlabel.font = [UIFont systemFontOfSize:13];
  18. self.botlabel.center = self.contentView.center;
  19. [self.contentView addSubview:_botlabel];
  20. }
  21. return self;
  22. }
  23. -(void)setIsSel:(BOOL)isSel{
  24. _isSel = isSel;
  25. if (isSel) {
  26. _botlabel.textColor = [UIColor colorWithRed:186/255.0 green:174/255.0 blue:255/255.0 alpha:1.0];
  27. }else{
  28. _botlabel.textColor = [UIColor colorWithRed:44/255.0 green:46/255.0 blue:48/255.0 alpha:1.0];
  29. }
  30. }
  31. @end
  32. #pragma mark - PFBottomColletionView
  33. @interface PFBottomColletionView()<UICollectionViewDataSource, UICollectionViewDelegate>
  34. @property (strong, nonatomic) UICollectionView *collection;
  35. @property (assign, nonatomic) NSInteger selIndex;
  36. @end
  37. @implementation PFBottomColletionView
  38. static NSString *cellID = @"bottomCell";
  39. - (id)initWithFrame:(CGRect)frame
  40. {
  41. self = [super initWithFrame:frame];
  42. if (self){
  43. self.backgroundColor = [UIColor colorWithRed:5/255.0 green:15/255.0 blue:20/255.0 alpha:0.74];
  44. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  45. layout.minimumInteritemSpacing = 0;
  46. layout.minimumLineSpacing = 16;
  47. layout.itemSize = CGSizeMake(60, 49);
  48. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  49. _collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, frame.size.height) collectionViewLayout:layout];
  50. _collection.backgroundColor = [UIColor clearColor];
  51. _collection.delegate = self;
  52. _collection.dataSource = self;
  53. [self addSubview:_collection];
  54. [_collection registerClass:[FUBottomBottomCell class] forCellWithReuseIdentifier:cellID];
  55. _collection.backgroundColor = [UIColor clearColor];
  56. self.backgroundColor = [UIColor clearColor];
  57. }
  58. return self;
  59. }
  60. -(void)setDataArray:(NSArray*)dataArray{
  61. _dataArray = dataArray;
  62. [self.collection reloadData];
  63. }
  64. #pragma mark --- UICollectionViewDataSource
  65. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  66. return _dataArray.count;
  67. }
  68. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  69. FUBottomBottomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  70. // cell.botlabel.text = NSLocalizedString(self.dataArray[indexPath.row].title, nil);
  71. cell.isSel = _selIndex == indexPath.row ? YES:NO;
  72. return cell;
  73. }
  74. #pragma mark --- UICollectionViewDelegateFlowLayout
  75. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  76. _selIndex = indexPath.row;
  77. [_collection reloadData];
  78. if ([self.delegate respondsToSelector:@selector(BottomColletionDidSelectedIndex:)]) {
  79. [self.delegate bottomColletionDidSelectedIndex:_selIndex];
  80. }
  81. }
  82. @end