ios - 快速滑动删除按钮的自定义高度

标签 ios iphone swift uitableview

我有自定义表格单元格。每个单元格都有不同的高度。我想给带有单元格高度的滑动删除按钮。

I have attached screen shot for

我在单元格中使用过 View 。 View 高度是单元格高度 - 16。上下边距 8。

所以请帮我做这件事。

最佳答案

在您的 Custom Cell Swift 类中使用此代码

override func layoutSubviews() {
    let fltHeight:CGFloat = 46
    var subviews: [Any] = self.subviews
    let subview: UIView? = subviews[0] as? UIView
    if NSClassFromString("UITableViewCellDeleteConfirmationView") != nil {
        if (subview?.isKind(of: NSClassFromString("UITableViewCellDeleteConfirmationView")!))! {
            let deleteButtonView: UIView? = (subview?.subviews[0])
            var buttonFrame: CGRect? = deleteButtonView?.frame
            buttonFrame?.origin.x = (deleteButtonView?.frame.origin.x)!
            buttonFrame?.origin.y = (deleteButtonView?.frame.origin.y)!
            buttonFrame?.size.width = (deleteButtonView?.frame.size.width)!
            buttonFrame?.size.height = fltHeight
            deleteButtonView?.frame = buttonFrame!

            // Placing at the center of the cell.
            subview?.frame = CGRect(x: CGFloat((subview?.frame.origin.x)!),
                                    y: CGFloat((subview?.frame.origin.y)! + ((subview?.frame.size.height)!-fltHeight)/2),
                                    width: CGFloat((subview?.frame.size.width)!),
                                    height: CGFloat(fltHeight))
            deleteButtonView?.clipsToBounds = true
            subview?.clipsToBounds = true
        }
    }
}

关于ios - 快速滑动删除按钮的自定义高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37719670/

相关文章:

ios - 以编程方式从 UITableViewController 将 UIImage 设置为 UITableView 的背景

ios - React Native [[DEFAULT]] firebaseapp 未初始化react-native-firebase

ios - 如何使用 uiactivityviewcontroller 将文本或自定义 url 分享到 facebook?

iphone - 在 iPhone 的 LinkedIn 集成中共享视频 URL

iOS Swift 代码 - 当我有一个断点时才工作

ios - WKWebView:从 iOS 中的文档文件夹加载内容

iphone - 找不到 cassert 文件,但我使用 Box2d 模板

swift - 根据可选案例值切换测试非可选

Swift 字典键类型

ios - 如何在iOS swift中隐藏/查看标题 View 表