在我的应用程序中,我将我的TableViewCell
定制为显示为卡片。我还为这些单元格实现了自定义UITableViewRowActions
。然而,这些动作看起来很奇怪,因为我添加了一个图层,使单元格看起来像浮动卡片。
Here's what it looks like这是我的cellForRowAt
函数的代码。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "someCell", for: indexPath) as! CustomCell
cell.delegate = self
cell.backgroundColor = .clear
cell.contentView.backgroundColor = .clear
let whiteRoundedView: UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: cell.frame.size.height - 20))
whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 2.0
whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1)
whiteRoundedView.layer.shadowOpacity = 0.2
cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubview(toBack: whiteRoundedView)
cell.updateCell()
return cell
}
而我的UITableViewRowAction
功能。预警:我正在使用这个SwipeCellKit存储库
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
if orientation == .left {
guard isSwipeRightEnabled else { return nil }
let completeAction = SwipeAction(style: .default, title: "Complete") { (action, index) in
print("complete!")
}
completeAction.backgroundColor = .green
return [completeAction]
} else {
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, index) in
print("delete")
}
return [deleteAction]
}
}
有没有办法调整UITableViewRowAction
的大小以适应细胞的模具?
如果不对框架进行一些更改,目前是不可能的。
我确实计划在SwipeTableViewCellDelegate
上添加一些方法,这些方法会在显示之前暴露每个UIButton
,并且当刷卡继续发生时。我想这会给你足够的灵活性来实现你的布局。
在此期间,这对你自己的叉子来说不应该太难。具体来说,看看SwipeTableViewCell
方法中的configureActionView
。它创建了SwipeActionsView
,它具有buttons
属性,包含滑动UIButton
子类。您只需将这些内容公开给您的应用即可。
如果有人在2019年仍在寻找解决方案,您可以使用不可见的unicode字符来设置宽度。
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"\u2060\t\t\t\u2060" handler: [self handler]];