# LBHorizontalCollectionViewLayout **Repository Path**: liuboliu/lbhorizontal-collection-view-layout ## Basic Information - **Project Name**: LBHorizontalCollectionViewLayout - **Description**: 一个支持多行横向滚动的自定义collectionViewlayout, 支持自定义行数,支持计算总体内容高度,一键导入 pod 'LBHorizontalCollectionViewLayout' - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-09-20 - **Last Updated**: 2021-09-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: 自定义多行横向滚动layout, 横向layout ## README # LBHorizontalCollectionViewLayout [![CI Status](https://img.shields.io/travis/liuboliu/LBHorizontalCollectionViewLayout.svg?style=flat)](https://travis-ci.org/liuboliu/LBHorizontalCollectionViewLayout) [![Version](https://img.shields.io/cocoapods/v/LBHorizontalCollectionViewLayout.svg?style=flat)](https://cocoapods.org/pods/LBHorizontalCollectionViewLayout) [![License](https://img.shields.io/cocoapods/l/LBHorizontalCollectionViewLayout.svg?style=flat)](https://cocoapods.org/pods/LBHorizontalCollectionViewLayout) [![Platform](https://img.shields.io/cocoapods/p/LBHorizontalCollectionViewLayout.svg?style=flat)](https://cocoapods.org/pods/LBHorizontalCollectionViewLayout) ## Example To run the example project, clone the repo, and run `pod install` from the Example directory first. ## Requirements ## Installation LBHorizontalCollectionViewLayout is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile: ```ruby pod 'LBHorizontalCollectionViewLayout' #使用方法 - (UICollectionView *)collectionView { if (!_collectionView) { LBHorizontalCollectionViewLayout *layout = [[LBHorizontalCollectionViewLayout alloc] init]; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); ///设置layout 的代理 layout.delegate = self; layout.sectionInset = UIEdgeInsetsMake(0, 0, 10, 0); _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])]; _collectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 10.0, *)) { _collectionView.prefetchingEnabled = NO; } else { // Fallback on earlier versions } _collectionView.backgroundColor = [UIColor cyanColor]; } return _collectionView; } #实现协议方法 #pragma mark - VVGeneralCategoryTopCellLayoutDeledate - (CGSize)itemSizeForItemInCollectionView:(UICollectionView *)collectionView layout:(LBHorizontalCollectionViewLayout *)collectionViewLayout { return CGSizeMake(CGRectGetWidth(self.view.bounds)/4.5, 97); } - (UIEdgeInsets)edgeInsetsForSectionInCollectionView:(UICollectionView *)collectionView layout:(LBHorizontalCollectionViewLayout *)collectionViewLayout { return UIEdgeInsetsMake(10, 0, 0, 0); } #计算collectionView的高度 (如果需要计算的话) LBMutilRowsHorizontalLayoutParameterModel *paramsModel = [[LBMutilRowsHorizontalLayoutParameterModel alloc] init]; paramsModel.itemCount = 50; paramsModel.itemSize = CGSizeMake(CGRectGetWidth(self.view.bounds)/4.5, 97); paramsModel.edgeInsetsForSection = UIEdgeInsetsMake(10, 0, 0, 0); paramsModel.boundWidthSubtractContentInset = CGRectGetWidth(self.view.bounds); CGFloat height = [LBHorizontalCollectionViewLayout heightOffContentWithLayoutParamsModel:paramsModel]; self.collectionView.frame = CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), height); ``` ![Image text](https://gitee.com/liuboliu/lbhorizontal-collection-view-layout/raw/master/2021-09-20%2015.14.57.gif) ## Author liuboliu, 2534660131@qq.com ## License LBHorizontalCollectionViewLayout is available under the MIT license. See the LICENSE file for more info.