【问题标题】:Swipable cell issue可滑动单元格问题
【发布时间】:2019-08-17 05:15:36
【问题描述】:

我想让单元格滑动功能像我的图像一样,我正在使用https://github.com/SwipeCellKit/SwipeCellKit,但由于我的单元格设计,我无法实现这种类型的功能。

尾部和底部有额外的空间,所以我的滑动动作不如我的设计那么完美。

我想要达到的目标。

到目前为止我所取得的成就

我怎样才能实现这种类型的功能,任何帮助将不胜感激。

【问题讨论】:

  • 你能告诉我你在故事板中的单元设计吗?

标签: ios swift uitableview swipe


【解决方案1】:

更新答案

在您的单元格设计中,白框在顶部、底部、左侧和右侧之间有一个空间。首先,使其完全覆盖在整个单元格的顶部和底部。并在单元格之间添加Cell Spacing

要存档此文件,您可以将页眉和页脚添加到 tableView

let cellSpaceHeight = 5

func numberOfSections(in tableView: UITableView) -> Int {
    return MenuArray!.count
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat(cellSpaceHeight)
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return CGFloat(cellSpaceHeight)
}

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let FooterView = UIView()
    FooterView.backgroundColor = UIColor.blue
    return FooterView
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = UIView()
    headerView.backgroundColor = UIColor.blue . //Set the color same as cell content background color
    return headerView
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 75
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
    guard orientation == .right else { return nil }

    let deleteAction = SwipeAction(style: .destructive, title: "Reminder") { action, indexPath in
        // handle action by updating model with deletion
    }
    // customize the action appearance
    deleteAction.image = UIImage(named: "events")
    deleteAction.backgroundColor = UIColor.purple

    return [deleteAction]
}
func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
    var options = SwipeOptions()
    options.expansionStyle = .destructive
    options.transitionStyle = .border
    return options
}

而我的tableviewCell.xib 是:

cell contentView 背景颜色设置为蓝色。并将tableView背景色改为Default

输出:

【讨论】:

  • 我不想覆盖整个单元格的前导、后移
  • 不要覆盖前导和尾随。覆盖顶部和底部
  • 并为单元格内容背景添加清晰的颜色,为表格视图背景颜色添加蓝色。
  • 你能给我做一个简单的演示吗?我想达到与我的截图相同的效果
  • 只需添加尾随约束并将其设置为零刷卡方法@JitendraModi,这个答案已经很完美了
猜你喜欢
  • 1970-01-01
  • 2014-11-18
  • 2016-02-19
  • 2021-09-18
  • 2018-07-22
  • 2015-11-07
  • 1970-01-01
  • 2014-03-21
  • 1970-01-01
相关资源
最近更新 更多