Swift-Declarative-Tables
简化了 Swift 4 表格的创建,使其更简单、声明性更强,类似于 React,使动态添加和删除部分和行变得简单。
只需将 pod 'SwiftyTables'
添加到您的 Podfile
。
无需再使用疯狂的开关和庞大的 UITableViewDelegates
方法!每个单元格的状态只在一个地方声明。
基于 Shopify 的 FunctionalTableData 构建而成。
我增加了以下功能:CarouselCell
,它是一个 CellConfigType
(即 FunctionalTableData 单元格),包含一个 UICollectionView
,其中只包含一种 UICollectionViewCell
。
CarouselItemCells
。只需将 UIVIew/UICollectionViewCell 遵循 NibView
/CarouselItemNibView
协议。
🌟 本演示🌟
MainViewController
具有多种类型单元格的 FunctionalTableData 演示。
TableViewController
当您点击时,可以插入和删除单元格的 FunctionalTableData 演示
CollectionViewController
CollectionTableData 演示,当您点击时,单元格可以插入和删除
一个通用的具有水平滚动或垂直非滚动的UICollectionView
的功能化表格单元格。每个CarouselCell
使用一个CarouselItemCell
类型。每个CarouselItemCell
是一个UICollectionViewCell
,且与它使用的ItemModel
类型相关联,此类型用于计算它的大小并配置其视图。
protocol CarouselItemCell where Self: UICollectionViewCell {
associatedtype ItemModel: Equatable'
static func sizeForItem(model: ItemModel, in collectionView: UICollectionView) -> CGSize
func configure(model: ItemModel)
static func scrollDirection() -> UICollectionViewScrollDirection
}
一个通过编程创建的滚动水平CarouselCell
。模型是一个自定义的UIColor
,用于设置CarouselItemColorTilesCell
的颜色。
let cell = CarouselColorTilesCell(
key: "colorTilesCell",
state: CarouselState<CarouselItemColorTilesCell>(
itemModels: [.red, .blue, .purple, .yellow, .green, .orange],
collectionHeight: 120,
didSelectItemCell: { indexPath in
print("Did tap item \(indexPath.row)")})
)
一个通过编程创建的不滚动垂直CarouselCell
。
let fourGridCell = resizableCell(key: "fourGridCell", color: .purple, height: 100, itemsPerRow: [1, 3])
let fiveGridCell = resizableCell(key: "fiveGridCell", color: .green, height: 100, itemsPerRow: [2, 3])
let tenGridCell = resizableCell(key: "tenGridCell", color: .blue, height: 100, itemsPerRow: [4, 3, 2, 1])
使用Storyboard创建的滚动水平CarouselCell
。
let dogeItemState = CarouselItemDetailState(image: #imageLiteral(resourceName: "finedog"), title: "Doge", subtitle: "This is fine")
let dogeCarousel = CarouselDetailCell(
key: "dogeCarousel",
state: CarouselState<CarouselItemDetailCell>(
itemModels: Array(repeating: dogeItemState, count: 20),
collectionHeight: 220,
didSelectItemCell: { index in
print("Did select doge at index \(index)") }))
详细单元格
使用故事板创建的 CellConfigType
。
let detailCell = DetailCell(
key: "detailCell",
state: DetailState(
image: #imageLiteral(resourceName: "finedog"),
title: "Sample Title",
subtitle: "This is the subs on a detail cell"))
标签单元格
通过程序创建的 CellConfigType
。
let labelCell = LabelCell(
key: "labelCell",
actions: CellActions(selectionAction: { _ in
print("label cell tapped")
return .deselected
}),
state: LabelState(text: "This is a LabelCell"))