以前写本身项目内部的应用调试工具箱:JXCaptain的时候。须要一个显示数据库的视图,须要有行列表头固定,而且表单内容能够上下左右滑动查看的特性,就像Excel视图同样。整个功能就只有一个ExcelView类,逻辑清晰简单,便于阅读和修改定制需求。git
JXExcelgithub
ExcelView
excel = ExcelView(frame: CGRect.zero)
excel.dataSource = self
excel.delegate = self
view.addSubview(excel)
复制代码
ExcelViewDataSource
代理方法func numberOfRows(in excelView: ExcelView) -> Int {
return 50
}
func numberOfColumns(in excelView: ExcelView) -> Int {
return 10
}
func excelView(_ excelView: ExcelView, columnNameAt column: Int) -> String {
return "col:\(column)"
}
func excelView(_ excelView: ExcelView, rowDataAt row: Int) -> [String] {
return dataSource[row]
}
func excelView(_ excelView: ExcelView, rowHeightAt row: Int) -> CGFloat {
return 40
}
func excelView(_ excelView: ExcelView, columnWidthAt column: Int) -> CGFloat {
return 120
}
func widthOfLeftHeader(in excelView: ExcelView) -> CGFloat {
return 50
}
func heightOfTopHeader(in excelView: ExcelView) -> CGFloat {
return 40
}
复制代码
ExcelViewDelegate
代理方法func excelView(_ excelView: ExcelView, didTapGridWith content: String) {
print("didTapGridWith:\(content)")
}
func excelView(_ excelView: ExcelView, didTapColumnHeaderWith name: String) {
print("didTapColumnHeaderWith:\(name)")
}
复制代码