菜鸟教程小白 发表于 2022-12-11 16:41:54

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


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

<p> <a href="/image/uZNGY.png" rel="noreferrer noopener nofollow"><img src="/image/uZNGY.png" alt="I have attached screen shot for"/></a> </p>

<p>我在单元格中使用了 View 。 View 高度为单元格高度 - 16。上下边距 8。</p>

<p>所以请帮我做这件事。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在您的自定义 Cell Swift 类中使用此代码</p>

<pre><code>override func layoutSubviews() {
    let fltHeight:CGFloat = 46
    var subviews: = self.subviews
    let subview: UIView? = subviews as? UIView
    if NSClassFromString(&#34;UITableViewCellDeleteConfirmationView&#34;) != nil {
      if (subview?.isKind(of: NSClassFromString(&#34;UITableViewCellDeleteConfirmationView&#34;)!))! {
            let deleteButtonView: UIView? = (subview?.subviews)
            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
      }
    }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 快速滑动删除按钮的自定义高度,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37719670/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37719670/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 快速滑动删除按钮的自定义高度