Ответ 1
Я нашел один способ его достижения.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if arrStudent.count > 0 {
let indexPath = NSIndexPath(row: 0, section: 0)
let cell = tblStudent.cellForRow(at: indexPath as IndexPath);
let swipeView = UIView()
swipeView.frame = CGRect(x: cell!.bounds.size.width, y: 0, width: 170, height: cell!.bounds.size.height)
swipeView.backgroundColor = .clear
let swipeEditLabel: UILabel = UILabel.init(frame: CGRect(x: 0, y: 0, width: 80, height: cell!.bounds.size.height))
swipeEditLabel.text = "Edit";
swipeEditLabel.textAlignment = .center
swipeEditLabel.font = UIFont.systemFont(ofSize: 19)
swipeEditLabel.backgroundColor = UIColor(red: 180/255, green: 180/255, blue: 180/255, alpha: 1) // Light Gray: Change color as you want
swipeEditLabel.textColor = UIColor.white
swipeView.addSubview(swipeEditLabel)
let swipeDeleteLabel: UILabel = UILabel.init(frame: CGRect(x: swipeEditLabel.frame.size.width, y: 0, width: 90, height: cell!.bounds.size.height))
swipeDeleteLabel.text = "Delete";
swipeDeleteLabel.textAlignment = .center
swipeDeleteLabel.font = UIFont.systemFont(ofSize: 19)
swipeDeleteLabel.backgroundColor = UIColor(red: 255/255, green: 41/255, blue: 53/255, alpha: 1) // Red color: Change color as you want
swipeDeleteLabel.textColor = UIColor.white
swipeView.addSubview(swipeDeleteLabel)
cell!.addSubview(swipeView)
UIView.animate(withDuration: 0.60, animations: {
cell!.frame = CGRect(x: cell!.frame.origin.x - 170, y: cell!.frame.origin.y, width: cell!.bounds.size.width + 170, height: cell!.bounds.size.height)
}) { (finished) in
UIView.animate(withDuration: 0.60, animations: {
cell!.frame = CGRect(x: cell!.frame.origin.x + 170, y: cell!.frame.origin.y, width: cell!.bounds.size.width - 170, height: cell!.bounds.size.height)
}, completion: { (finished) in
for subview in swipeView.subviews {
subview.removeFromSuperview()
}
swipeView.removeFromSuperview()
})
}
}
}
Добавьте пользовательский UIView
в конец ячейки и удалите его после завершения анимации.
- Вы можете установить собственный кадр представления, как хотите
- Добавьте метки (метки) с цветом фона и заголовком, как вы хотите.
Здесь вы должны написать код, который не каждый раз вызывает этот код в viewDidAppear
, он должен вызывать один раз только для индикации пользователя.