美文网首页
iOS:链式编程-collectionView组件化

iOS:链式编程-collectionView组件化

作者: 豆浆油条cc | 来源:发表于2019-10-28 14:41 被阅读0次

链式编程-tableview组件化:
https://github.com/qw9685/ccTableView.git

链式编程-collectionView组件化:
https://github.com/qw9685/ccCollectionView.git

Untitled.gif

最简单的实现:

-(ccCollectionView *)collectionView{
        if (_collectionView == nil) {
            _collectionView = [[ccCollectionView alloc] initCollectionViewWithItemClass:[UICollectionViewCell class] headClass:nil footClass:nil];
            _collectionView.layout.sectionInset = UIEdgeInsetsMake(15, 15, 30, 15);
            _collectionView.layout.itemSize = CGSizeMake(100, 100);
            _collectionView.layout.minimumInteritemSpacing = 15;
            _collectionView.layout.minimumLineSpacing = 15;
            _collectionView.cc_CollectionDidSelectRowAtIndexPath(^(NSIndexPath * _Nonnull indexPath, UICollectionView * _Nonnull collectionView) {
                
                [self.navigationController pushViewController:[firstViewController new] animated:YES];
                
            }).cc_CollectionNumberOfRows(^NSInteger(NSInteger section, UICollectionView * _Nonnull collectionView) {
                
                return 5;
                
            }).cc_CollectionViewForCell(^UICollectionViewCell * _Nonnull(NSIndexPath * _Nonnull indexPath, UICollectionView * _Nonnull collectionView) {
                
                UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
                
                UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
                label.text = @"自定义cell";
                label.backgroundColor = [UIColor redColor];
                [cell addSubview:label];
                return cell;
            });
        }
        
        return _collectionView;
}

自定义cell,header,footer

-(ccCollectionView *)collectionView{
        if (_collectionView == nil) {
            _collectionView = [[ccCollectionView alloc] initCollectionViewWithItemClass:[firstCollectionViewCell class] headClass:[firstCollectionReusableHeadView class] footClass:[firstCollectionReusableFootView class]];
            _collectionView.layout.headerReferenceSize = CGSizeMake(500, 66);
            _collectionView.layout.footerReferenceSize = CGSizeMake(500, 10);
            
            _collectionView.cc_sizeForItemAtIndexPath(^CGSize(UICollectionViewLayout * _Nonnull layout, NSIndexPath * _Nonnull indexPath) {
                
                return CGSizeMake(100, 110*2);
                
            }).cc_CollectionDidSelectRowAtIndexPath(^(NSIndexPath * _Nonnull indexPath, UICollectionView * _Nonnull collectionView) {
                
            }).cc_CollectionviewForElementOfKind(^UICollectionReusableView * _Nonnull(NSIndexPath * _Nonnull indexPath, NSString * _Nonnull kind, UICollectionView * _Nonnull collectionView) {
                //头部
               if ([kind isEqualToString: UICollectionElementKindSectionHeader]) {
                   firstCollectionReusableHeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier: NSStringFromClass([firstCollectionReusableHeadView class]) forIndexPath:indexPath];
                   view.backgroundColor = [UIColor yellowColor];
                return view;
               }else{
                    firstCollectionReusableFootView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier: NSStringFromClass([firstCollectionReusableFootView class]) forIndexPath:indexPath];
                    view.backgroundColor = [UIColor blackColor];
                   return view;
               }
            }).cc_CollectionNumberOfSections(^NSInteger(UICollectionView * _Nonnull collectionView) {
                return 3;
            }).cc_CollectionNumberOfRows(^NSInteger(NSInteger section, UICollectionView * _Nonnull collectionView) {
                return 5;
            }).cc_CollectionViewForCell(^UICollectionViewCell * _Nonnull(NSIndexPath * _Nonnull indexPath, UICollectionView * _Nonnull collectionView) {
                firstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([firstCollectionViewCell class]) forIndexPath:indexPath];
                cell.backgroundColor = [UIColor blueColor];
                return cell;
            });
        }
        
        return _collectionView;
}

相关文章

  • iOS:链式编程-collectionView组件化

    链式编程-tableview组件化:https://github.com/qw9685/ccTableView.g...

  • iOS:链式编程-tableView组件化

    什么是链式编程? 最简单的理解就是通过点语法,调用返回参数为相同对象的方法,通过这种方式,不断的点出方法拼接,最终...

  • 工作iOS技术总结

    链式编程、函数式、面向接口编程思想 iOS 之ReactiveCocoa 链式编程2 WKWebView的缓存处理...

  • ReactiveObjC入门

    ReactiveObjC基础用法 iOS开发三种编程方式(响应式编程、函数编程、链式编程),函数编程最常用,链式编...

  • 链式编程总结

    链式编程总结 @(iOS) 研究了一下链式编程,但是感觉项目中用处不是很多。 介绍 1.什么时候使用链式编程?在面...

  • iOS组件化

    iOS组件化 iOS组件化

  • iOS 链式编程简单的使用

    iOS 链式编程简单的使用 链式编程-顾名思义,链式,连贯性为其主要特征,放在编程领域来讲,说简单点就是把一系列的...

  • iOS-链式编程思想

    在iOS中,链式编程虽然用的不太多,但是,在特定的应用环境下,利用block实现链式编程的话,会大大的提高编程效率...

  • iOS链式编程

    在iOS中,链式编程虽然用的不太多,但是,在特定的应用环境下,利用block实现链式编程的话,会大大的提高编程效率...

  • iOS组件化方案

    iOS组件化方案 iOS组件化方案

网友评论

      本文标题:iOS:链式编程-collectionView组件化

      本文链接:https://www.haomeiwen.com/subject/mpcbvctx.html