BogoRechargePayMoneyCollection.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // BogoRechargePayCollection.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/4/8.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoRechargePayMoneyCollection.h"
  9. #import "BogoRechargePayMoneyCell.h"
  10. @implementation BogoRechargePayMoneyCollection
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. [self setUpView];
  16. }
  17. return self;
  18. }
  19. -(void)setUpView{
  20. self.backgroundColor = UIColor.clearColor;
  21. [self addSubview:self.titleL];
  22. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  23. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  24. // layout.headerReferenceSize=CGSizeMake(kScreenW, kRealValue(166));//头视图的大小
  25. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, self.titleL.bottom, kScreenW, self.height - self.titleL.height) collectionViewLayout:layout];
  26. _collectionView.tag = 1107;
  27. _collectionView.delegate = self;
  28. _collectionView.dataSource = self;
  29. _collectionView.backgroundColor = UIColor.clearColor;
  30. [_collectionView registerNib:[UINib nibWithNibName:@"BogoRechargePayMoneyCell" bundle:nil] forCellWithReuseIdentifier:@"BogoRechargePayMoneyCell"];
  31. _collectionView.scrollEnabled = NO;
  32. [self addSubview:self.collectionView];
  33. }
  34. - (void)setModel:(AccountRechargeModel *)model{
  35. _model = model;
  36. self.listArr = [NSMutableArray arrayWithArray:model.rule_list];
  37. for (int i = 0; i < self.listArr.count; i++) {
  38. PayMoneyModel *model = self.listArr[i];
  39. model.isSelect = NO;
  40. if (i == 0) model.isSelect = YES;
  41. [self.listArr replaceObjectAtIndex:i withObject:model];
  42. }
  43. self.selectModel = self.listArr.firstObject;
  44. NSInteger count = 0;
  45. if (self.model.rule_list.count%3 > 0) {
  46. count = self.model.rule_list.count/3 + 1;
  47. } else {
  48. count = self.model.rule_list.count/3;
  49. }
  50. self.collectionView.height = count * 90;
  51. [self.collectionView reloadData];
  52. }
  53. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  54. return 1;
  55. }
  56. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  57. return self.listArr.count;
  58. }
  59. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  60. BogoRechargePayMoneyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BogoRechargePayMoneyCell" forIndexPath:indexPath];
  61. cell.model = self.listArr[indexPath.row];
  62. return cell;
  63. }
  64. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  65. PayMoneyModel *selectModel = self.listArr[indexPath.row];
  66. selectModel.isSelect = YES;
  67. for (int i = 0; i < self.listArr.count; i++) {
  68. PayMoneyModel *model = self.listArr[i];
  69. model.isSelect = NO;
  70. if (selectModel.payID == model.payID) {
  71. selectModel.isSelect = YES;
  72. [self.listArr replaceObjectAtIndex:i withObject:selectModel];
  73. }
  74. }
  75. self.selectModel = selectModel;
  76. [self.collectionView reloadData];
  77. }
  78. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  79. return CGSizeMake((kScreenW-11 * 2 - 12 * 2)/3, kRealValue(70));
  80. }
  81. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  82. return 10;
  83. }
  84. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  85. {
  86. return UIEdgeInsetsMake(10, 10, 10, 10);
  87. }
  88. -(UILabel *)titleL{
  89. if (!_titleL) {
  90. _titleL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(15), -8, kScreenW * 0.6, kRealValue(25))];
  91. _titleL.text = ASLocalizedString(@"请选择支付金额");
  92. _titleL.font = [UIFont systemFontOfSize:16];
  93. _titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  94. }
  95. return _titleL;
  96. }
  97. @end