在我的应用程序中,我TableViewCell
将我的自定义设置为像卡片一样显示。我还UITableViewRowActions
为这些单元实现了自定义。然而,这些动作看起来很奇怪,因为我添加了一个图层以使单元格看起来像一张浮动卡片。
这是它的样子
这是我的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
以适应电池的模具?