使用 Xcode 项目时
使用 Swift Package Manager 清单时
选择一个 package 版本
2.0.1
master
SwiftTableViewGroup 是符合 SwiftUI 设计的 UITableView 和 UICollectionView 数据驱动(SwiftTableViewGroup is a UITableView and UICollectionView data driver compliant with SwiftUI design)
typora-copy-images-to | typora-root-url |
---|---|
../SwiftTableViewGroup/images/ |
../SwiftTableViewGroup |
❇️
SwiftTableViewGroup
使用最新的 Swift5.1 语法@_functionBuilder
结合最新的SwiftUI
设计模式开发。❇️
SwiftTableViewGroup
是利用最新的Swift.1
语法@_functionBuilder
符合SwiftUI
设计的数据驱动。
[TOC]
- 支持
UICollectionView
数据驱动 - 更改
Api
使用更简单 - 支持自定义高度或者大小
- 使用更加安全
https://github.com/josercc/SwiftTableViewGroup
pod 'SwiftTableViewGroup'
github "josercc/SwiftTableViewGroup"
Xcode 11
Swift 5.1
let tableView = UITableView()
var dataSource = TableView(tableView:tableView)
/// setup configuration(初始化配置)
dataSource.setup {
/// Add Header
TableViewHeaderFooterView
/// Add Cell
TableViewCell
/// Add More Cell
...
/// Add Footer
TableViewHeaderFooterView
}
/// Perform registration and refresh(执行注册和刷新)
dataSource.reloadData
TableCell { content, contentCell in
/// Create a configured block(创建配置的 Block)
content.configuration(UITableViewCell.self) { (cell, index) in
cell.textLabel?.text = self.source[index]
cell.accessoryType = .disclosureIndicator
}
/// Create a clickback call block(创建点击回调 Block)
content.didSelectRow(UITableViewCell.self) { (cell, index) in
}
}
.number(self.source.count)
.height(45)
}
self.dataSource.reloadData()
let settingDataSource = TableView(tableView: tableView)
settingDataSource.setup {
/// Create `SettingHeaderView` Header(创建自定义`SettingHeaderView`Header)
TableHeaderView(SettingHeaderView.self, { content,contentHeader in
content.configuration(SettingHeaderView.self) { (view, section) in
view.textLabel?.text = "Header"
}
})
.height(49)
/// Create `IntrinsicContentTextLabelCell` Cell(创建`IntrinsicContentTextLabelCell`Cell)
TableCell(IntrinsicContentTextLabelCell.self)
/// Create Dynamic change number Cell(创建动态更改数量的 Cell)
TableCell { content,contentCell in
content.configuration(UITableViewCell.self) { (cell, index) in
cell.textLabel?.text = "\(index) 点击我会增加哦"
}
content.didSelectRow(UITableViewCell.self) { (cell, index) in
let number = contentCell.number + 1;
contentCell.number(number)
settingDataSource.reloadData()
}
}
.height(44)
/// Create Dynamic change height Cell)(创建动态更改高度的 Cell)
TableCell { content,contentCell in
content.configuration(UITableViewCell.self) { (cell, index) in
cell.textLabel?.text = "点击我改变高度"
}
content.didSelectRow(UITableViewCell.self) { (cell, index) in
let height = contentCell.height == 44 ? 100 : 44;
contentCell.height(CGFloat(height))
settingDataSource.reloadData()
}
}
.height(44)
}
self.dataSource.setup {
/// Create normal class `UICollectionViewCell` cell(创建默认为`UITableViewCell`类的 Cell)
CollectionCell { content, cellContent in
content.configuration(UICollectionViewCell.self) { (cell, index) in
cell.backgroundColor = index % 2 == 0 ? UIColor.red : UIColor.blue
}
content.didSelectRow(UICollectionViewCell.self) { (cell, index) in
cell.backgroundColor = cell.backgroundColor == UIColor.red ? UIColor.blue : UIColor.red
}
}
.number(20)
.size(CGSize(width: 100, height: 200))
}
.inset(UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))
self.dataSource.reloadData()
您可以更改 TableView 的 Sections 数组的另一侧的元素属性,然后调用
reloadData
。
public struct ScrollViewDelegate {
public var scrollViewDidScroll:((_ scrollView: UIScrollView) -> Void)?
public var scrollViewWillBeginDragging:((_ scrollView: UIScrollView) -> Void)?
public var scrollViewWillEndDragging:((_ scrollView: UIScrollView, _ velocity: CGPoint, _ targetContentOffset: UnsafeMutablePointer<CGPoint>) -> Void)?
public var scrollViewDidEndDragging:((_ scrollView: UIScrollView, _ decelerate: Bool) -> Void)?
public var scrollViewWillBeginDecelerating:((_ scrollView: UIScrollView) -> Void)?
public var scrollViewDidEndDecelerating:((_ scrollView: UIScrollView) -> Void)?
}
可以实现
UITableView
的上述代理方法
示例
tableView.scrollDelegate?.scrollViewDidScroll = { scrollView in
}
可以提交 PR 或提 ISSUSE
- 高度或者大小的设置优先级
- 高度 ( UITableViewCell/UITableHeaderFooterView )
- 自定义 > 设置 > 自动获取 (sizeToFit)
- 大小 (UICollectionViewCell/UICollectionReusableView)
- 自定义 > 设置 > FlowLayout
- 高度 ( UITableViewCell/UITableHeaderFooterView )
- Email: josercc@163.com