UITableView定制左滑效果

本文介绍如何使用UITableViewRowAction类来实现 UITableView 的横向滑动效果。通过设置按钮样式、标题和颜色等属性,并定义点击事件处理方法,可以轻松地为应用中的表格视图添加自定义的滑动操作。

定制左滑效果
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. 初始化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)
    ```
    
  2. 实现代理方法

    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
         return self.actions
    }
    

转载于:https://www.cnblogs.com/huahuahu/p/UITableView-ding-zhi-zuo-hua-xiao-guo.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值