[英]custom height for swipe delete button swift
I have custom table cell. 我有自定义表格单元格。 Each cell have different height.
每个单元都有不同的高度。 I want to give swipe delete button with cell height.
我想给滑动删除按钮以单元格高度。
I have used view in cell. 我已经在单元格中使用过视图。 View height is cell height - 16. Top-bottom margin 8.
视图高度是像元高度-16.上下边距8。
So please help me to do this. 所以请帮我做到这一点。
Use this code in your Custom Cell Swift class 在您的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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.