轻量级自定义集合视图,灵感来自 Airbnb。
ASCollectionView 版本 | 最低 iOS 目标版本 | Swift 版本 |
---|---|---|
1.4.0 | 10.0 | 5.x |
1.1.0 | 9.0 | 4.2 |
1.0.9 | 9.0 | 4.1 |
1.0.8 | 9.0 | 4.0 |
1.0.7 | 9.0 | 3.x |
1.0.2 | 8.0 | 2.x |
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 ASCollectionView 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'ASCollectionView', '1.4.0'
end
然后,运行以下命令
$ pod install
Carthage 是一个分散的依赖管理器,它构建您的依赖项并为您提供二进制框架。
您可以使用 Homebrew 安装 Carthage,使用以下命令
brew update
brew install carthage
要使用 Carthage 将 ASCollectionView 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它
github "abdullahselek/ASCollectionView" ~> 1.4.0
运行 carthage update 来构建框架,并将构建好的 ASCollectionView.framework 拖入您的 Xcode 项目。
修改您的 Package.swift 文件以包含以下依赖项
.package(url: "https://github.com/abdullahselek/ASCollectionView.git", from: "1.4.0")
运行 swift package resolve
XCFrameworks 需要 Xcode 11 或更高版本,并且集成与 .framework 格式的集成非常相似。请使用脚本 scripts/build-framework.sh 来生成二进制 ASCollectionView.xcframework 归档文件,您可以在 Xcode 中将其用作依赖项。
ASCollectionView.xcframework 是一个 Release (优化) 二进制文件,提供最佳的 Swift 代码性能。
demo 文件夹中有一个示例 viewcontroller,我在下面添加了一些示例代码。
您可以将 collectionview 添加到您的 storyboard、xib 文件或以编程方式添加,然后设置约束。返回到您的 viewcontroller 并实现自定义的数据源和委托方法。
class ViewController: UIViewController, ASCollectionViewDataSource, ASCollectionViewDelegate {
...
override func viewDidLoad() {
super.viewDidLoad()
collectionView.registerNib(UINib(nibName: collectionElementKindHeader, bundle: nil), forSupplementaryViewOfKind: collectionElementKindHeader, withReuseIdentifier: "header")
collectionView.delegate = self
collectionView.asDataSource = self
}
// MARK: ASCollectionViewDataSource
func numberOfItemsInASCollectionView(asCollectionView: ASCollectionView) -> Int {
return numberOfItems
}
func collectionView(asCollectionView: ASCollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let gridCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! GridCell
gridCell.label.text = NSString(format: "Item %ld ", indexPath.row) as String
gridCell.imageView.image = UIImage(named: NSString(format: "image-%ld", indexPath.row % 10) as String)
return gridCell
}
func collectionView(asCollectionView: ASCollectionView, parallaxCellForItemAtIndexPath indexPath: NSIndexPath) -> ASCollectionViewParallaxCell {
let parallaxCell = collectionView.dequeueReusableCellWithReuseIdentifier("parallaxCell", forIndexPath: indexPath) as! ParallaxCell
parallaxCell.label.text = NSString(format: "Item %ld ", indexPath.row) as String
parallaxCell.updateParallaxImage(UIImage(named: NSString(format: "image-%ld", indexPath.row % 10) as String)!)
return parallaxCell
}
func collectionView(asCollectionView: ASCollectionView, headerAtIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryViewOfKind(ASCollectionViewElement.Header, withReuseIdentifier: "header", forIndexPath: indexPath)
return header
}
func loadMoreInASCollectionView(asCollectionView: ASCollectionView) {
if numberOfItems > 30 {
collectionView.enableLoadMore = false
return
}
numberOfItems += 10
collectionView.loadingMore = false
collectionView.reloadData()
}
GridCell collectionview cell 在示例中使用
class GridCell: UICollectionViewCell {
@IBOutlet var label: UILabel!
@IBOutlet var imageView: UIImageView!
}
ParallaxCell 在示例中使用
class ParallaxCell: ASCollectionViewParallaxCell {
@IBOutlet var label: UILabel!
}
Copyright (c) 2016 Abdullah Selek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Inspired by Airbnb and ninjaprox. Improved and all coded in new programming
language Swift.