欢迎光临
我们一直在努力

【Swift】ASCollectionView

建站超值云服务器,限时71元/月

【Swift】ASCollectionView

项目介绍:

ASCollectionView

https://github.com/abdullahselek/ASCollectionView

使用Swift collectionView模仿Airbnb的布局。

Screenshots

portrait

landscape

Requirements 环境需求

iOS 8.0+

CocoaPods 通过 cocopods导入

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:


$ gem install cocoapods

For Swift 3

You can use 1.0.3

For Swift 2.3

Please use 1.0.2

To integrate ASCollectionView into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ASCollectionView', '1.0.1'
end

Then, run the following command:

$ pod install

Carthage 通过 Carthage 进行集成

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

Carthage是一个依赖管理器,它构建了你的依赖并为你提供了框架。
您可以使用以下命令使用Homebrew安装Carthage

brew update
brew install carthage

To integrate ASCollectionView into your Xcode project using Carthage, specify it in your Cartfile:
要使用Carthage将ASCollectionView集成到您的Xcode项目中,请在Cartfile中写下以下代码:

github "abdullahselek/ASCollectionView" ~> 1.0.4

Run carthage update to build the framework and drag the built ASCollectionView.framework into your Xcode project.
执行命令 carthage update 来构建框架并将 ASCollectionView.framework拖动到你的Xcode项目中。

Example Usage

There is a sample viewcontroller inside demo folder and I added some sample code below.

You can add collectionview to your storyboard, xib file or add programmatically and then set constraints. Turn back to your
viewcontroller and implement custom datasource and delegate methods.

在demo文件夹中有一个示例viewcontroller,我在下面添加了一些示例代码。
您可以向storyboard,xib文件添加collectionview或以代码形式添加,然后设置约束。 回到你的
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 used in sample

    class GridCell: UICollectionViewCell {
    
        @IBOutlet var label: UILabel!
        @IBOutlet var imageView: UIImageView!
    
    }

ParallaxCell used in sample

    class ParallaxCell: ASCollectionViewParallaxCell {
    
        @IBOutlet var label: UILabel!
    
    }

![code4app]()



赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 【Swift】ASCollectionView
分享到: 更多 (0)