AccordionSwift 2.0.3

AccordionSwift 2.0.3

Victor Sigler 维护。



Accordion Custom Image

Pods Version Swift Version License Type


用于在项目中集成的手风琴/下拉菜单库。这个库以协议为导向、类型安全,新版本受到 Jesse Squires 的 JSQDataSourcesKit 的启发。.

主要特性
📱 兼容 iPhone / iPad
🔨 完全可定制的单元格
🚒 支持设备旋转
🔥 完全用 Swift 编写

需求💥

  • iOS 10.0+
  • Xcode 10.2+

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它

$ gem install cocoapods

CocoaPods 1.1.0+ 是构建 AccordionSwift 2.0.0+ 所必需的。

要使用 CocoaPods 将 AccordionSwift 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

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

target '<Your Target Name>' do
    pod 'AccordionSwift', '~> 2.0.0'
end

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖管理器,它会构建您的依赖项并提供二进制框架。要将 AccordionSwift 集成到您的 Xcode 项目中使用 Carthage,请在您的 Cartfile 中指定它

github "Vkt0r/AccordionSwift" ~> 2.0.0

使用

导入框架后,这个库可以在 UITableViewControllerUIViewController 中使用,并提供了对单元格和数据源的完全自定义。

import UIKit
import AccordionSwift

class AccordionViewController: UIViewController {
    
    // MARK: - IBOutlets
    
    @IBOutlet weak var tableView: UITableView!
    
    // MARK: - Typealias
    
    typealias ParentCellModel = Parent<GroupCellModel, CountryCellModel>
    typealias ParentCellConfig = CellViewConfig<ParentCellModel, UITableViewCell>
    typealias ChildCellConfig = CellViewConfig<CountryCellModel, CountryTableViewCell>
    
    // MARK: - Properties
    
    /// The Data Source Provider with the type of DataSource and the different models for the Parent and Chidl cell.
    var dataSourceProvider: DataSourceProvider<DataSource<ParentCellModel>, ParentCellConfig, ChildCellConfig>?
    
    // MARK: - UIViewController
    
    override func viewDidLoad() {
        super.viewDidLoad()
        configDataSource()
        
        navigationItem.title = "World Cup 2018"
    }
}

以上示例显示如何分别为父单元格和子单元格定义 CellViewConfig,以及如何定义 Parent 模型。

/// Defines a cell config type to handle a UITableViewCell
public protocol CellViewConfigType {
    
    // MARK: Associated types
    
    /// The type of elements backing the collection view or table view.
    associatedtype Item
    
    /// The type of views that the configuration produces.
    associatedtype Cell: UITableViewCell
    
    // MARK: Methods
    
    func reuseIdentiferFor(item: Item?, indexPath: IndexPath) -> String
    
    @discardableResult
    func configure(cell: Cell, item: Item?, tableView: UITableView, indexPath: IndexPath) -> Cell
}

另一个步骤是定义负责处理数据源和每个单元格的 DataSourceProvider。该 DataSourceProvider 提供了 numberOfExpandedParentCells 属性,可以用于更改折叠面板的行为,使其一次只打开一个 single 项目或在任何给定时间打开多个项目。请注意,默认行为是打开多个项目。

有关更详细的说明,请参阅 示例 项目。

截图

screenshot

一次打开多个单元格的示例

screenshot

一次只打开一个单元格的示例

screenshot

待办

  • 为库添加单元测试。
  • 添加CircleCI集成。

反馈

我发现了一个错误,或有一个功能请求

请提交一个GitHub 问题😱

想贡献吗?

太好了!请发起一个pull request👍


许可证

MIT 许可证。更多信息请参阅 LICENSE 文件