Swift - изменить размер слайда, чтобы удалить кнопку в tableView - PullRequest
0 голосов
/ 30 апреля 2018

Есть ли способ изменить размер кнопки удаления для слайда для удаления в табличном представлении? Я сделал свои собственные границы для ячейки, поэтому кнопка удаления распространяется на границу так:

enter image description here

Соответствующий код ниже:

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in

            self.reminders.remove(at: indexPath.row)
            tableView.reloadData()

        }

        deleteAction.backgroundColor = .red

        let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
        return configuration
    }

1 Ответ

0 голосов
/ 30 апреля 2018

Попробуйте это Обновленный ответ

override func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
    self.tableView.subviews.forEach { subview in
        print("YourTableViewController: \(String(describing: type(of: subview)))")
        if (String(describing: type(of: subview)) == "UISwipeActionPullView") {
            if (String(describing: type(of: subview.subviews[0])) == "UISwipeActionStandardButton") {
                var deleteBtnFrame = subview.subviews[0].frame
                deleteBtnFrame.origin.y = 12
                deleteBtnFrame.size.height = 155


                // Subview in this case is the whole edit View
                subview.frame.origin.y =  subview.frame.origin.y + 12
                subview.frame.size.height = 155
                subview.subviews[0].frame = deleteBtnFrame
                subview.backgroundColor = UIColor.yellow
            }
        }
    }
}

Высота ячейки табличного представления

Установить высоту ограничения представления таблицы:

heightOfTableViewConstraint = NSLayoutConstraint(item: self.tableView, attribute: .height, relatedBy: .equal, toItem: containerView, attribute: .height, multiplier: 0.0, constant: 1000)
containerView.addConstraint(heightOfTableViewConstraint)

Вызовите tableView.layoutIfNeeded () и по завершении найдите видимые ячейки, суммируйте их высоту и отредактируйте heightOfTableViewConstraint:

UIView.animate(withDuration: 0, animations: {
    self.tableView.layoutIfNeeded()
    }) { (complete) in
        var heightOfTableView: CGFloat = 0.0
        // Get visible cells and sum up their heights
        let cells = self.tableView.visibleCells
        for cell in cells {
            heightOfTableView += cell.frame.height
        }
        // Edit heightOfTableViewConstraint's constant to update height of table view
        self.heightOfTableViewConstraint.constant = heightOfTableView
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...