TCSCustomRowActionFactory
TCSCustomRowActionFactory 允许您使用UIView和其他方便的方法以任何方式设置表格视图中单元格的滑动动作(参见Habrahabr上的相关文章)
使用方法和示例
TCSCustomRowActionFactory 主要设计用于简化标准 UITableViewRowAction 的配置(因为它强加了很多限制),同时也支持新的 ContextualAction(iOS 11 及以上版本)。要实现 TCSCustomRowActionFactory,您只需要在表格代理的方法中创建一个 TCSCustomRowActionFactory 实例,然后用我们的自定义视图配置它,并返回所需的对象(.rowAction() 或 .contextualAction(for: indexPath),具体取决于表格代理方法)
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
guard let cell = tableView.cellForRow(at: indexPath) else { return nil }
var rowActions: [UITableViewRowAction] = []
let rowActionFactory = TCSCustomRowActionFactory { indexPath in
tableView.setEditing(false, animated: true)
}
let rowActionView = <...> // create row action view
rowActionView.backgroundColor = .green
rowActionFactory.setupForCell(with: rowActionView)
if let rowAction = rowActionFactory.rowAction() {
rowActions.append(rowAction)
}
return rowActions
}
方法
有一些方法可以设置 TCSCustomRowActionFactory
func setupForCell(with view: UIView)
func setupForCell(withImage image: UIImage, size: CGSize, backgroundColor: UIColor = .white)
func setupForCell(withImage image: UIImage, size: CGSize, backgroundColor: UIColor = .white, contentInsets: UIEdgeInsets = .zero)
func setupForCell(withImage image: UIImage, size: CGSize, backgroundColor: UIColor = .white, contentInsets: UIEdgeInsets = .zero, isScaleProportionally: Bool = true)
func setupForCell(withTitle title: String, image: UIImage, size: CGSize, backgroundColor: UIColor, titleAttributes: [NSAttributedStringKey : Any]? = nil, contentInsets: UIEdgeInsets? = nil)
示例
要运行示例项目,首先从仓库克隆,然后在 Example 目录中运行 pod install
要求
安装
TCSCustomRowActionFactory 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行
pod 'TCSCustomRowActionFactory'
贡献
当然!请发送一个拉取请求或提出一个问题。了解如何改进总是好的,耶!
作者
Alexander Trushin,[email protected]
许可
TCSCustomRowActionFactory 在 Apache License, Version 2.0 下提供。有关更多信息,请参阅 LICENSE 文件。