• h3_676892
  • 57.3KB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-06-14 20:39
KRLCollectionViewGridLayout 此布局是UICollectionViewFlowLayout的替代方案,后者使用已定义的列数和长宽比属性来确定项目的大小和大小,从而强制单元格的大小,而不是通过单元格的大小来指示布局如何定位(UICollectionViewFlowLayout的行为方式) 。 默认情况下,无论集合视图有多大,它都将连续显示相同数量的项目。 您可以指定每行的项目数以及所有项目的所需长宽比(无论滚动方向如何,始终为宽/高): layout.numberOfItemsPerLine = 5; layout.aspectRatio = 16.0/9.0; 您可以指定类似于UICollectionViewFlowLayout的指标,如下所示: layout.sectionInset = UIEdgeInsetsMake(10,20,30,40); la
# KRLCollectionViewGridLayout [![Build Status](]( [![Version](]( [![](]( [![Carthage compatible](]( [![License](]( [![Platform](]( This layout is an alternative to UICollectionViewFlowLayout that positions and sizes items using a defined number of columns and an aspect ratio property which force the size of cells, rather than the cells' size telling the layout how to position them (in the way UICollectionViewFlowLayout behaves). By default, this will always show the same number of items in a row no matter how large or small the collection view is. You can specify the number of items per line and the desired aspect ratio of all items (which is always width / height, regardless of scroll direction): layout.numberOfItemsPerLine = 5; layout.aspectRatio = 16.0/9.0; You can specify metrics similar to UICollectionViewFlowLayout, like so: layout.sectionInset = UIEdgeInsetsMake(10,20,30,40); layout.interitemSpacing = 15; layout.lineSpacing = 5; layout.scrollDirection = UICollectionViewScrollDirectionVertical; You can also add headers and footers to each section similar to UICollectionViewFlowLayout: layout.headerReferenceLength = 44; layout.footerReferenceLength = 100; In vertical scrolling mode, length is the height of the header/footer. In horizontal scrolling mode, length is the width of the header/footer. A length of 0 in these dimensions will not try to create a view. All of the above properties (except for `scrollDirection`) can be configured on a per-section basis using `KRLCollectionViewDelegateGridLayout`. Have your view controller or other object that implements the regular UICollectionViewDelegate also implement this protocol to make these per-section variances for these properties happen. ## Usage To run the example project, clone the repo, and run `pod install` from the Example directory first. You can either run unit tests on the library itself, or run the sample project for a visual demonstration. ## Requirements * iOS 6.0 * tvOS 9.0 Example project requires Xcode 8.0+, can only run in iOS 8.0+ or tvOS 9.0+. ## Installation ### CocoaPods KRLCollectionViewGridLayout is available through [CocoaPods]( To install it, simply add the following line to your Podfile: pod "KRLCollectionViewGridLayout", "~> 1.0.0" ### Carthage You can also install it via [Carthage]( To do so, add the following to your Cartfile: github "klundberg/KRLCollectionViewGridLayout" ~> 1.0.0 ## Author Kevin Lundberg, kevin at klundberg dot com ## Contributions Pull requests are welcome! Please include unit tests for any bugfixes or new features. ## License KRLCollectionViewGridLayout is available under the MIT license. See the LICENSE file for more info.