美文网首页
自定义tableView左滑删除按钮

自定义tableView左滑删除按钮

作者: 丶月月鸟 | 来源:发表于2019-11-13 15:25 被阅读0次
    import UIKit
    
    class RefreshAndEditingTableView: RefreshTableView {
    
        override func layoutSubviews() {
            super.layoutSubviews()
            
            if #available(iOS 11.0, *) {
                for subview in self.subviews where subview.isKind(of: NSClassFromString("UISwipeActionPullView")!) {
                    subview.backgroundColor = RGBA(242, g: 242, b: 242, a: 1)
                    
                    for view in subview.subviews where view.isKind(of: NSClassFromString("UISwipeActionStandardButton")!) {
                        
                        view.backgroundColor = RGBA(242, g: 242, b: 242, a: 1)
                        
                        let deleteBtn = setupDeleteBtn(frame: CGRect(x: 0, y: 0, width: 80, height: view.bounds.height))
                        view.addSubview(deleteBtn)
                        view.bringSubviewToFront(deleteBtn)
                    }
                }
                
            } else {    // IOS 10以及以下
                for subview in subviews where subview.isKind(of: NSClassFromString("UITableViewCellDeleteConfirmationView")!) {
                    subview.backgroundColor = RGBA(242, g: 242, b: 242, a: 1)
                    
                    for view in subview.subviews where view.isKind(of: UIButton.self) {
                        view.backgroundColor = RGBA(242, g: 242, b: 242, a: 1)
                        
                        let deleteBtn = setupDeleteBtn(frame: view.frame)
                        view.addSubview(deleteBtn)
                        view.bringSubviewToFront(deleteBtn)
                    }
                }
            }
        }
        
        
        private func setupDeleteBtn(frame: CGRect) -> UIButton {
            
            let deleteBtn = UIButton(type: .custom)
            deleteBtn.frame = frame
            deleteBtn.backgroundColor = RGBA(242, g: 242, b: 242, a: 1)
            deleteBtn.setImage(UIImage(named: "btn_home_footmark_delete"), for: .normal)
            deleteBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
            return deleteBtn
        }
    
    }
    
    

    相关文章

      网友评论

          本文标题:自定义tableView左滑删除按钮

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