| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- //
- // BGRoomSetChannelCell.m
- // UniversalApp
- //
- // Created by bugu on 2020/3/23.
- // Copyright © 2020 voidcat. All rights reserved.
- //
- #import "BGRoomSetChannelCell.h"
- #import "BGRoomSetChannelCollectCell.h"
- @implementation BGRoomSetChannelCell
- {
- UILabel *_micLable;
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- [self initUI];
- }
- return self;
- }
- - (void)initUI {
-
-
- self.backgroundColor = kClearColor;
- self.contentView.backgroundColor = kClearColor;
- self.bgImageView = ({
- UIImageView * imageView = [[UIImageView alloc]init];
- imageView.backgroundColor = [UIColor whiteColor];
- imageView;
- });
- ViewRadius(self.bgImageView, 10);
- [self.contentView addSubview:self.bgImageView];
- [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 10, 10, 10));
- }];
-
- _micLable = [[UILabel alloc] init];
- _micLable.text = ASLocalizedString(@"麦位数量");
- _micLable.textColor = kWhiteColor;
- _micLable.font = [UIFont systemFontOfSize:16];
- [self.contentView addSubview:_micLable];
- [_micLable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImageView).offset(10);
- make.left.equalTo(self.bgImageView).offset(10);
- }];
-
- self.bgImageView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.15];
-
-
- [self.contentView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(_micLable.mas_bottom).offset(10);
- make.left.equalTo(self.bgImageView).offset(8);
- make.right.equalTo(self.bgImageView).offset(-8);
- make.height.equalTo(self.bgImageView).offset(-33-12);
- }];
-
-
- }
- - (void)setChannelDataArray:(NSArray *)channelDataArray{
- _channelDataArray = channelDataArray;
-
- self.collectionView.height = self.height;
-
-
- [self.collectionView reloadData];
- }
- - (void)setVoice_type:(NSString *)voice_type{
- _voice_type = voice_type;
- // for (NSInteger i = 0; i < self.channelDataArray.count; i++) {
- // VideoClassifiedModel *model = self.channelDataArray[i];
- // if ([model.id isEqualToString:voice_type]) {
- // model.isSelected = YES;
- //
- // }
- // }
- [self.collectionView reloadData];
- }
- #pragma mark - UICollectionViewDelegate
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.channelDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- BGRoomSetChannelCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([BGRoomSetChannelCollectCell class]) forIndexPath:indexPath];
- [cell setModel:self.channelDataArray[indexPath.item]];
- return cell;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
- return CGSizeMake( floor(( kScreenW - 20*2 ) / 3 - 12*2), 30);
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
- return 12;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
- return 12;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
- return UIEdgeInsetsMake(0, 20, 10, 20);
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- VideoClassifiedModel *model = self.channelDataArray[indexPath.item];
-
- if (model.isSelected) {
-
- model.isSelected = NO;
- if (self.selectedChannel) {
- self.selectedChannel(nil);
- }
- [collectionView reloadData];
-
- }else{
-
- for (VideoClassifiedModel *typeModel in self.channelDataArray) {
- typeModel.isSelected = (typeModel == model);
-
- if (typeModel.isSelected) {
- if (self.selectedChannel) {
- self.selectedChannel(typeModel);
- }
- }
- }
- [collectionView reloadData];
-
- }
- }
- - (UICollectionView *)collectionView{
- if (!_collectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
- _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, self.height) collectionViewLayout:layout];
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- _collectionView.backgroundColor = kClearColor;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.scrollEnabled = NO;
- [_collectionView registerClass:[BGRoomSetChannelCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([BGRoomSetChannelCollectCell class])];
-
- }
- return _collectionView;
- }
- @end
|