美文网首页
UITableView定制左滑效果

UITableView定制左滑效果

作者: 我是花老虎 | 来源:发表于2016-07-31 14:11 被阅读54次
定制左滑效果
  1. UITableViewRowAction类

object defines a single action to present when the user swipes horizontally in a table

类的属性

  • style: UITableViewRowActionStyle
    按钮的style,defaultnormal效果如上图
  • title: String?
    按钮的标题啦
  • backgroundColor: UIColor?
    按钮的颜色

初始化方法

convenience init(style: UITableViewRowActionStyle, title: String?, handler: (UITableViewRowAction, IndexPath) -> Void)

handler即使点击时调用的方法。

  1. 如何实现效果
  2. 初始化UITableViewRowAction
      let action1 = UITableViewRowAction.init(style: .Normal, title: "normal") { (action, path) in
      }
      let action2 = UITableViewRowAction.init(style: .Default, title: "default") { (action, path) in
          self.titles.removeAtIndex(0)
          self.tableView?.deleteRowsAtIndexPaths([path], withRowAnimation: .Fade)
      }
      self.actions.insert(action1, atIndex: 0)
      self.actions.insert(action2, atIndex: 1)
  1. 实现代理方法
    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
         return self.actions
    }

相关文章

网友评论

      本文标题:UITableView定制左滑效果

      本文链接:https://www.haomeiwen.com/subject/bootsttx.html