Skip to content

cj1024/CJCollectionViewAdapter

Repository files navigation

CJCollectionViewAdapter

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

CJCollectionViewAdapter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CJCollectionViewAdapter'

Basic Usage

  1. Init
- (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;
}
  1. Setup Sections
- (void)viewControllerReloadData {
    [self.adapter updateSections:@[ [TestSectionDataA new], [TestSectionDataB new], [TestSectionDataC new] ... ]];
}
  1. Implement DataSource And Delegate Methods If Necessary In SectionData

ScreenShot

ScreenShot1

Author

cj1024, [email protected]

License

CJCollectionViewAdapter is available under the MIT license. See the LICENSE file for more info.

About

Adapter Help To Make Using UICollectionView Easily

Resources

License

Stars

Watchers

Forks

Packages

No packages published