BGRoomSetChannelCell.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // BGRoomSetChannelCell.m
  3. // UniversalApp
  4. //
  5. // Created by bugu on 2020/3/23.
  6. // Copyright © 2020 voidcat. All rights reserved.
  7. //
  8. #import "BGRoomSetChannelCell.h"
  9. #import "BGRoomSetChannelCollectCell.h"
  10. @implementation BGRoomSetChannelCell
  11. {
  12. UILabel *_micLable;
  13. }
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. // Initialization code
  17. }
  18. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  19. [super setSelected:selected animated:animated];
  20. // Configure the view for the selected state
  21. }
  22. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  23. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  24. [self initUI];
  25. }
  26. return self;
  27. }
  28. - (void)initUI {
  29. self.backgroundColor = kClearColor;
  30. self.contentView.backgroundColor = kClearColor;
  31. self.bgImageView = ({
  32. UIImageView * imageView = [[UIImageView alloc]init];
  33. imageView.backgroundColor = [UIColor whiteColor];
  34. imageView;
  35. });
  36. ViewRadius(self.bgImageView, 10);
  37. [self.contentView addSubview:self.bgImageView];
  38. [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 10, 10, 10));
  40. }];
  41. _micLable = [[UILabel alloc] init];
  42. _micLable.text = ASLocalizedString(@"麦位数量");
  43. _micLable.textColor = kWhiteColor;
  44. _micLable.font = [UIFont systemFontOfSize:16];
  45. [self.contentView addSubview:_micLable];
  46. [_micLable mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.top.equalTo(self.bgImageView).offset(10);
  48. make.left.equalTo(self.bgImageView).offset(10);
  49. }];
  50. self.bgImageView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.15];
  51. [self.contentView addSubview:self.collectionView];
  52. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.equalTo(_micLable.mas_bottom).offset(10);
  54. make.left.equalTo(self.bgImageView).offset(8);
  55. make.right.equalTo(self.bgImageView).offset(-8);
  56. make.height.equalTo(self.bgImageView).offset(-33-12);
  57. }];
  58. }
  59. - (void)setChannelDataArray:(NSArray *)channelDataArray{
  60. _channelDataArray = channelDataArray;
  61. self.collectionView.height = self.height;
  62. [self.collectionView reloadData];
  63. }
  64. - (void)setVoice_type:(NSString *)voice_type{
  65. _voice_type = voice_type;
  66. // for (NSInteger i = 0; i < self.channelDataArray.count; i++) {
  67. // VideoClassifiedModel *model = self.channelDataArray[i];
  68. // if ([model.id isEqualToString:voice_type]) {
  69. // model.isSelected = YES;
  70. //
  71. // }
  72. // }
  73. [self.collectionView reloadData];
  74. }
  75. #pragma mark - UICollectionViewDelegate
  76. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  77. return self.channelDataArray.count;
  78. }
  79. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  80. BGRoomSetChannelCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([BGRoomSetChannelCollectCell class]) forIndexPath:indexPath];
  81. [cell setModel:self.channelDataArray[indexPath.item]];
  82. return cell;
  83. }
  84. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  85. return CGSizeMake( floor(( kScreenW - 20*2 ) / 3 - 12*2), 30);
  86. }
  87. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  88. return 12;
  89. }
  90. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  91. return 12;
  92. }
  93. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  94. return UIEdgeInsetsMake(0, 20, 10, 20);
  95. }
  96. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  97. VideoClassifiedModel *model = self.channelDataArray[indexPath.item];
  98. if (model.isSelected) {
  99. model.isSelected = NO;
  100. if (self.selectedChannel) {
  101. self.selectedChannel(nil);
  102. }
  103. [collectionView reloadData];
  104. }else{
  105. for (VideoClassifiedModel *typeModel in self.channelDataArray) {
  106. typeModel.isSelected = (typeModel == model);
  107. if (typeModel.isSelected) {
  108. if (self.selectedChannel) {
  109. self.selectedChannel(typeModel);
  110. }
  111. }
  112. }
  113. [collectionView reloadData];
  114. }
  115. }
  116. - (UICollectionView *)collectionView{
  117. if (!_collectionView) {
  118. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  119. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, self.height) collectionViewLayout:layout];
  120. _collectionView.delegate = self;
  121. _collectionView.dataSource = self;
  122. _collectionView.backgroundColor = kClearColor;
  123. _collectionView.showsVerticalScrollIndicator = NO;
  124. _collectionView.scrollEnabled = NO;
  125. [_collectionView registerClass:[BGRoomSetChannelCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([BGRoomSetChannelCollectCell class])];
  126. }
  127. return _collectionView;
  128. }
  129. @end