CJCollectionViewAdapter
示例
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
需求
安装
CJCollectionViewAdapter 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'CJCollectionViewAdapter'
基本用法
- 初始化
- (CJCollectionViewAdapter *)adapter {
if (_adapter == nil) {
CJCollectionViewAdapter *adapter = [[CJCollectionViewAdapter alloc] init];
_adapter = adapter;
}
return _adapter;
}
- (UICollectionView *)collectionView {
if (_collectionView == nil) {
UICollectionView *aView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.adapter.wrappedCollectionViewLayout];
[self.adapter attachCollectionView:aView];
aView.alwaysBounceVertical = YES;
aView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];
if (@available(iOS 11.0, *)) {
aView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
if (@available(iOS 13.0, *)) {
aView.automaticallyAdjustsScrollIndicatorInsets = NO;
}
aView.mj_header = [MJRefreshStateHeader headerWithRefreshingTarget:self refreshingAction:@selector(viewControllerShouldReloadData)];
aView.mj_footer = [MJRefreshAutoStateFooter footerWithRefreshingTarget:self refreshingAction:@selector(viewControllerShouldLoadMoreData)];
_collectionView = aView;
}
return _collectionView;
}
- 设置分区
- (void)viewControllerReloadData {
[self.adapter updateSections:@[ [TestSectionDataA new], [TestSectionDataB new], [TestSectionDataC new] ... ]];
}
- 在 SectionData 中根据需要实现 DataSource 和 Delegate 方法
屏幕截图
作者
cj1024, [email protected]
许可证
CJCollectionViewAdapter 在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。