测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Wonder Bear 维护。
ActionCell,封装 UITableViewCell 以包含操作,无需继承 UITableViewCell,使用滑动触发操作(类似于 Mailbox App)。我喜欢它。
从版本 2.0 开始,ActionCell 框架进行了重新设计,所以 API 与 2.* 版本与 1.* 版本不同,如果您之前使用过旧版本,您必须进行一些更改,但不需要太多。
如果您不希望使用任何依赖项管理器,可以手动将 ActionCell 集成到您的项目中。
打开示例项目,构建并运行。
public protocol ActionCellDelegate: NSObjectProtocol {
var tableView: UITableView! { get }
/// Do something when action triggered
func didActionTriggered(cell: UITableViewCell, action: String)
}
public protocol ActionControlDelegate: NSObjectProtocol {
func didActionTriggered(action: String)
}
public protocol ActionSheetDelegate: NSObjectProtocol {
/// Setup action sheet
func setupActionsheet(side: ActionSide, actions: [ActionControl])
/// Open action sheet
func openActionsheet(side: ActionSide, completionHandler: (() -> ())?)
/// Close action sheet
func closeActionsheet(_ completionHandler: (() -> ())?)
}
extension ViewController: ActionCellDelegate {
public func didActionTriggered(cell: UITableViewCell, action: String) {
...
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseId")!
... (cell customization)
// create wrapper
let wrapper = ActionCell()
// set delegate
wrapper.delegate = self
// set animationStyle
wrapper.animationStyle = .ladder
// wrap cell with actions
wrapper.wrap(cell: cell,
actionsLeft: [
{
let action = IconTextAction(action: "cell 0 -- left 0")
action.icon.image = #imageLiteral(resourceName: "image_5").withRenderingMode(.alwaysTemplate)
action.icon.tintColor = UIColor.white
action.label.text = "Hello"
action.label.font = UIFont.systemFont(ofSize: 12)
action.label.textColor = UIColor.white
action.backgroundColor = UIColor(red:0.14, green:0.69, blue:0.67, alpha:1.00)
return action
}(),
{
let action = TextAction(action: "cell 0 -- left 1")
action.label.text = "Long Sentence"
action.label.font = UIFont.systemFont(ofSize: 12)
action.label.textColor = UIColor.white
action.backgroundColor = UIColor(red:1.00, green:0.78, blue:0.80, alpha:1.00)
return action
}(),
{
let action = IconAction(action: "cell 0 -- left 2")
action.icon.image = #imageLiteral(resourceName: "image_0").withRenderingMode(.alwaysTemplate)
action.icon.tintColor = UIColor.white
action.backgroundColor = UIColor(red:0.51, green:0.83, blue:0.73, alpha:1.00)
return action
}(),
],
actionsRight: [
{
let action = IconTextAction(action: "cell 0 -- right 0")
action.icon.image = #imageLiteral(resourceName: "image_1").withRenderingMode(.alwaysTemplate)
action.icon.tintColor = UIColor.white
action.label.text = "Hello"
action.label.font = UIFont.systemFont(ofSize: 12)
action.label.textColor = UIColor.white
action.backgroundColor = UIColor(red:0.14, green:0.69, blue:0.67, alpha:1.00)
return action
}(),
{
let action = TextAction(action: "cell 0 -- right 1")
action.label.text = "Long Sentence"
action.label.font = UIFont.systemFont(ofSize: 12)
action.label.textColor = UIColor.white
action.backgroundColor = UIColor(red:0.51, green:0.83, blue:0.73, alpha:1.00)
return action
}(),
{
let action = IconAction(action: "cell 0 -- right 2")
action.icon.image = #imageLiteral(resourceName: "image_2").withRenderingMode(.alwaysTemplate)
action.icon.tintColor = UIColor.white
action.backgroundColor = UIColor(red:1.00, green:0.78, blue:0.80, alpha:1.00)
return action
}(),
])
return cell
}
! 注意:为了使 UITableViewCell 在重用中正常运行,您应该重写 prepareForReuse 方法并调用 clearActionsheet 方法
override func prepareForReuse() {
super.prepareForReuse()
clearActionsheet() // remove actionCell view from cell
}
IconAction, TextAction 以及 IconTextAction 已实现,您可以直接使用它们,或者可以选择使用 ActionControlDelegate 来创建自己的 ActionControl。
var animationStyle: AnimationStyle = ladder | ladder_emergence | concurrent // Action animation style
var animationDuration: TimeInterval = 0.3 // duration of the animation
var enableDefaultAction: Bool // Enable default action trigger when the content panned to far enough, if true, the first action (on left: the leftest one, on right: the rightest one) will be the default action.
var defaultActionTriggerPropotion: CGFloat // The propotion of (state public to state trigger-prepare / state public to state trigger), about where the default action triggered
func wrap(cell target: UITableViewCell, actionsLeft: [ActionControl] = [], actionsRight: [ActionControl] = [])
init(action: String, width: CGFloat = 80, iconSize: CGSize = CGSize(width: 20, height: 20))
init(action: String, width: CGFloat = 80)
init(action: String, width: CGFloat = 80, iconSize: CGSize = CGSize(width: 20, height: 20), space: CGFloat = 5, offset: CGFloat = -3)
var isActionSheetOpened: Bool
func setupActionsheet(side: ActionSide, actions: [ActionControl] = []) // Change actionsheet's actions
func openActionsheet(side: ActionSide, completionHandler: (() -> ())? = nil)
func closeActionsheet(_ completionHandler: (() -> ())? = nil)
xiongxiong,[href="/cdn-cgi/l/email-protection#b3b7b1b5b8b6b2a6b8b2b7b1b1c5b9b1b3a6decebeef3beb3"][__cf_email__][email protected]
ActionCell 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。