SwiftDataTables
允许您在 iOS 中以美观的表格形式显示类似网格的数据集。对最终用户的主要目标是能够通过以下功能尽快从表中获取有用的信息:排序、搜索和分页;并为开发人员提供易于实现的选项,具有可扩展的配置。
主要功能包括:
- 已在 iOS 8.0、9、10、11 和 12 以上的版本上进行测试。
- 完全支持 Swift 5
- 兼容移动设备。表格会适应视口大小。
- 即时搜索。通过文本搜索过滤结果。
- 支持左右两侧固定/冻结列。
- 持续支持和积极开发!
- 完全支持数据源和委托!
- 提供演示项目,展示所有类型的自定义
- 或者可以传递易于配置的插件对象,其中包含默认值,以自定义您的 Swift 数据表的视觉表示。
- 可以扫描所有字段,以过滤数据源。
- 可以按智能方式对表格中的各种类型的数据进行排序,检测数字和字符串
- 列宽和行高可配置,或根据内容自动进行比例缩放
- 提供行和列选择的美丽交替颜色。
- 包括搜索视图中完全可配置的页眉和页脚标签。
- 和美丽整洁的展示。
安装
Carthage
- 将以下内容添加到您的 Cartfile:
github "pavankataria/SwiftDataTables"
- 然后运行
carthage update
- 有关最新安装说明,请遵循 Carthage 的 README 中的当前说明。
CocoaPods
- 将以下内容添加到您的 Podfile:
pod 'SwiftDataTables'
- 您还需要确保选择使用框架:
use_frameworks!
- 然后运行
pod install
。
包含示例项目
要运行示例项目,请按照以下步骤操作
- 下载或克隆仓库 (
git clone https://github.com/pavankataria/SwiftDataTables
) - 进入
DemoSwiftDataTables/Example
文件夹 (cd SwiftDataTables/Example
) - 在已安装 Xcode 9 的情况下,正常打开
SwiftDataTables.xcodeproj
项目 - 构建并运行。
如果您有任何问题或建议,请提交带有适当标签的问题,我会立即回复您。谢谢
配置
可以设置一个配置对象来对数据表进行快速选项设置。或者您可以使用代理方法进行动态选项更改。
数据源方法。
这是一个可选的数据源实现,您也可以按照Demo项目中的示例,使用静态数据集初始化您的SwiftDataTable
,从而避免实现数据源。但如果您想展示更动态的内容,请使用以下SwiftDataTableDataSource
协议。
public protocol SwiftDataTableDataSource: class {
/// The number of columns to display
func numberOfColumns(in: SwiftDataTable) -> Int
/// Return the total number of rows that will be displayed in the table
func numberOfRows(in: SwiftDataTable) -> Int
/// Return the data for the given row
func dataTable(_ dataTable: SwiftDataTable, dataForRowAt index: NSInteger) -> [DataTableValueType]
/// The header title for the column position to be displayed
func dataTable(_ dataTable: SwiftDataTable, headerTitleForColumnAt columnIndex: NSInteger) -> String
}
用于最大定制化的Delegate
一个可选的Delegate,用于进一步的定制。默认值将通过SwiftDataTableConfiguration文件获取。这些值可以被覆盖并传递到SwiftDataTable构造函数中,如果您不希望使用Delegate。
@objc public protocol SwiftDataTableDelegate: class {
/// Fired when a cell is selected.
///
/// - Parameters:
/// - dataTable: SwiftDataTable
/// - indexPath: the index path of the row selected
@objc optional func didSelectItem(_ dataTable: SwiftDataTable, indexPath: IndexPath)
/// Fired when a cell has been deselected
///
/// - Parameters:
/// - dataTable: SwiftDataTable
/// - indexPath: the index path of the row deselected
@objc optional func didDeselectItem(_ dataTable: SwiftDataTable, indexPath: IndexPath)
/// Specify custom heights for specific rows. A row height of 0 is valid and will be used.
@objc optional func dataTable(_ dataTable: SwiftDataTable, heightForRowAt index: Int) -> CGFloat
/// Specify custom widths for columns. This method once implemented overrides the automatic width calculation for remaining columns and therefor widths for all columns must be given. This behaviour may change so that custom widths on a single column basis can be given with the automatic width calculation behaviour applied for the remaining columns.
@objc optional func dataTable(_ dataTable: SwiftDataTable, widthForColumnAt index: Int) -> CGFloat
/// Column Width scaling. If set to true and the column's total width is smaller than the content size then the width of each column will be scaled proprtionately to fill the frame of the table. Otherwise an automatic calculated width size will be used by processing the data within each column.
/// Defaults to true.
@objc optional func shouldContentWidthScaleToFillFrame(in dataTable: SwiftDataTable) -> Bool
/// Section Header floating. If set to true headers can float and remain in view during scroll. Otherwise if set to false the header will be fixed at the top and scroll off view along with the content.
/// Defaults to true
@objc optional func shouldSectionHeadersFloat(in dataTable: SwiftDataTable) -> Bool
/// Section Footer floating. If set to true footers can float and remain in view during scroll. Otherwise if set to false the footer will be fixed at the top and scroll off view along with the content.
/// Defaults to true.
@objc optional func shouldSectionFootersFloat(in dataTable: SwiftDataTable) -> Bool
/// Search View floating. If set to true the search view can float and remain in view during scroll. Otherwise if set to false the search view will be fixed at the top and scroll off view along with the content.
// Defaults to true.
@objc optional func shouldSearchHeaderFloat(in dataTable: SwiftDataTable) -> Bool
/// Disable search view. Hide search view. Defaults to true.
@objc optional func shouldShowSearchSection(in dataTable: SwiftDataTable) -> Bool
/// The height of the section footer. Defaults to 44.
@objc optional func heightForSectionFooter(in dataTable: SwiftDataTable) -> CGFloat
/// The height of the section header. Defaults to 44.
@objc optional func heightForSectionHeader(in dataTable: SwiftDataTable) -> CGFloat
/// The height of the search view. Defaults to 44.
@objc optional func heightForSearchView(in dataTable: SwiftDataTable) -> CGFloat
/// Height of the inter row spacing. Defaults to 1.
@objc optional func heightOfInterRowSpacing(in dataTable: SwiftDataTable) -> CGFloat
/// Control the display of the vertical scroll bar. Defaults to true.
@objc optional func shouldShowVerticalScrollBars(in dataTable: SwiftDataTable) -> Bool
/// Control the display of the horizontal scroll bar. Defaults to true.
@objc optional func shouldShowHorizontalScrollBars(in dataTable: SwiftDataTable) -> Bool
/// Control the background color for cells in rows intersecting with a column that's highlighted.
@objc optional func dataTable(_ dataTable: SwiftDataTable, highlightedColorForRowIndex at: Int) -> UIColor
/// Control the background color for an unhighlighted row.
@objc optional func dataTable(_ dataTable: SwiftDataTable, unhighlightedColorForRowIndex at: Int) -> UIColor
/// Return the number of fixed columns
@objc optional func fixedColumns(for dataTable: SwiftDataTable) -> DataTableFixedColumnType
/// Return `true` to support RTL layouts by flipping horizontal scroll on `CollectionViewFlowLayout`, if the current interface direction is RTL.
@objc optional func shouldSupportRightToLeftInterfaceDirection(in dataTable: SwiftDataTable) -> Bool
}
参与进来
- 如果您想贡献代码,请随时提交pull请求。
- 如果您有功能请求,请开一个issue。
- 如果您发现了bug,在提交issue之前,请检查旧issue。
- 如果您需要帮助或想要提出一些一般问题,请创建一个issue。
在贡献之前,请查看CONTRIBUTING文件获取更多信息。
如果您在您的应用中使用SwiftDataTables
,我们很想听听您的反馈!在twitter上给我留言。
作者
Pavan Kataria
👨💻 贡献者
Sebastien Senechal Hais Daekin
许可证
SwiftDataTables可在MIT许可证下获得。有关更多信息,请参阅LICENSE文件。该软件包受到了JQuery的DataTables插件的启发。