SwiftyTables 1.0.0

SwiftyTables 1.0.0

Paige Sun 维护。



  • Paige Sun

Swift-Declarative-Tables

简化了 Swift 4 表格的创建,使其更简单、声明性更强,类似于 React,使动态添加和删除部分和行变得简单。

只需将 pod 'SwiftyTables' 添加到您的 Podfile

无需再使用疯狂的开关和庞大的 UITableViewDelegates 方法!每个单元格的状态只在一个地方声明。

基于 Shopify 的 FunctionalTableData 构建而成。

我增加了以下功能:🌟一个易于使用的泛型 CarouselCell,它是一个 CellConfigType(即 FunctionalTableData 单元格),包含一个 UICollectionView,其中只包含一种 UICollectionViewCell

🌟示例单元格和视图控制器演示了如何使用 FunctionalTableData。

🌟可以 programically 或使用 nib 创建自定义单元格、标题和 CarouselItemCells。只需将 UIVIew/UICollectionViewCell 遵循 NibView/CarouselItemNibView 协议。

🌟估计单元格、部分和标题的高度。

🌟本演示🌟

MainViewController

具有多种类型单元格的 FunctionalTableData 演示。

TableViewController

当您点击时,可以插入和删除单元格的 FunctionalTableData 演示或者🗑.

CollectionViewController

CollectionTableData 演示,当您点击时,单元格可以插入和删除或者🗑.

CarouselCell

一个通用的具有水平滚动或垂直非滚动的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

一个通过编程创建的滚动水平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)")})
)

Color Tiles CarouselCell

CarouselCell

一个通过编程创建的不滚动垂直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])

Vertical Grid Cell

CarouselCell

使用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)") }))

CarouselDetailCell

详细单元格

使用故事板创建的 CellConfigType

let detailCell = DetailCell(
	key: "detailCell",
	state: DetailState(
		image: #imageLiteral(resourceName: "finedog"),
		title: "Sample Title",
		subtitle: "This is the subs on a detail cell"))

LabelCell

标签单元格

通过程序创建的 CellConfigType

let labelCell = LabelCell(
	key: "labelCell",
	actions: CellActions(selectionAction: { _ in
		print("label cell tapped")
		return .deselected
	}),
	state: LabelState(text: "This is a LabelCell"))

LabelCell