| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // MORoomBackgroundSetView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/8/13.
- //
- #define kCollectionViewLeftAndRight 15.0
- #import "MORoomBackgroundSetView.h"
- @interface MORoomBackgroundSetView ()<UICollectionViewDelegate,UICollectionViewDataSource>
- /** 主界面 */
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation MORoomBackgroundSetView
- - (instancetype)init{
- self = [super init];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
- [self addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(15.0);
- make.width.equalTo(self).offset(-15.0);
- make.top.bottom.equalTo(self);
- }];
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (void)listWillAppear{
-
- }
- - (UIView *)listView{
- return self;
- }
- - (void)setDataArr:(NSArray *)dataArr{
- _dataArr = dataArr;
-
- if(dataArr.count != 0){
- [self.collectionView reloadData];
- }
- }
- #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.dataArr.count;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- MOMicroStyleModel *model = self.dataArr[indexPath.row];
- MORoomBackgroundCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MORoomBackgroundCell_ID forIndexPath:indexPath];
- cell.cellModel = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
-
- for (MOMicroStyleModel *model in self.dataArr) {
- model.isChoose = NO;
- }
-
- MOMicroStyleModel *model = self.dataArr[indexPath.row];
- model.isChoose = YES;
- [self.collectionView reloadData];
-
- self.didSelectCellBlock ? self.didSelectCellBlock(model) : nil;
-
- }
- #pragma mark Lazy
- - (UICollectionView *)collectionView
- {
- if (!_collectionView)
- {
- CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2;
-
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- layout.minimumLineSpacing = 16.0;
- layout.minimumInteritemSpacing = 15.0;
-
- CGFloat width = (collectionWidth - 16.0 * 3.0) / 4.0;
- CGFloat height = width * 94.0 / 74.0;
-
- layout.itemSize = CGSizeMake(width ,height);
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, collectionWidth, collectionWidth) collectionViewLayout:layout];
- [_collectionView registerNib:[UINib nibWithNibName:@"MORoomBackgroundCell" bundle:nil] forCellWithReuseIdentifier:MORoomBackgroundCell_ID];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.layer.cornerRadius = 12.0;
- _collectionView.layer.masksToBounds = YES;
- _collectionView.backgroundColor = [UIColor clearColor];
- _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
- }
- return _collectionView;
- }
- @end
|