| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // MOLanguageItemView.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/9.
- //
- #import "MOLanguageItemView.h"
- #import "MOLanguageItemCell.h"
- @implementation MOLanItemModel
- @end
- @interface MOLanguageItemView ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *collectionView;///<主视图
- @end
- @implementation MOLanguageItemView
- - (instancetype)initWithFrame:(CGRect)frame{
-
- if (self = [super initWithFrame:frame])
- {
- self.backgroundColor = [UIColor clearColor];
- self.layer.cornerRadius = 12.0;
- self.layer.masksToBounds = YES;
-
- [self setupUI];
- }
- return self;
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- self.backgroundColor = [UIColor clearColor];
- self.layer.cornerRadius = 12.0;
- self.layer.masksToBounds = YES;
-
- [self setupUI];
- }
- - (void)layoutSubviews{
- [super layoutSubviews];
- }
- - (void)setupUI
- {
- [self addSubview:self.titleLab];
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.mas_equalTo(26.0);
- make.top.equalTo(self).offset(14.0);
- make.right.mas_equalTo(-9.0);
- make.height.mas_greaterThanOrEqualTo(18.0);
- }];
-
- [self addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make){
- make.top.equalTo(self.titleLab.mas_bottom).offset(15);
- make.left.equalTo(self).offset(24.0);
- make.right.equalTo(self).offset(-24.0);
- make.bottom.equalTo(self);
- }];
- }
- - (void)setDataArr:(NSMutableArray *)dataArr
- {
- _dataArr = dataArr;
- [self.collectionView reloadData];
- }
- #pragma mark --UICollectionViewDatasource & delegate
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.dataArr.count;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
-
- MOCountryList *itemModel = self.dataArr[indexPath.row];
- MOLanguageItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOLanguageItemCell_ID forIndexPath:indexPath];
- cell.model = itemModel;
-
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
-
- MOCountryList *itemModel = self.dataArr[indexPath.row];
- for (MOCountryList *model in self.dataArr) {
- model.isChoose = NO;
- }
- itemModel.isChoose = YES;
- [self.collectionView reloadData];
-
- self.selectBlock ? self.selectBlock(itemModel) : nil;
- }
- #pragma mark - Lazy
- - (UILabel *)titleLab
- {
- if (!_titleLab)
- {
- _titleLab = [[UILabel alloc] init];
- _titleLab.text = @"";
- _titleLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
- _titleLab.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];
- _titleLab.textAlignment = NSTextAlignmentLeft;
- _titleLab.numberOfLines = 0;
-
- }
- return _titleLab;
- }
- - (UICollectionView *)collectionView
- {
- if (!_collectionView)
- {
- UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
-
- CGFloat width = (SCREENWIDTH - 39.0 * 2.0 - 10) / 2.0;
- CGFloat height = 30.0;
-
- flow.itemSize = CGSizeMake(width, height);
- flow.minimumLineSpacing = 10;//行间距
- flow.minimumInteritemSpacing = 10;//列间距
- flow.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, (SCREENWIDTH - 12.0 * 2), 100) collectionViewLayout:flow];
- _collectionView.allowsMultipleSelection = YES;
- _collectionView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
-
- [_collectionView registerClass:[MOLanguageItemCell class] forCellWithReuseIdentifier:MOLanguageItemCell_ID];
- _collectionView.layer.masksToBounds = YES;
- _collectionView.layer.cornerRadius = 13;
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- }
- return _collectionView;
- }
-
- @end
|