0

I've transformed the tableview and tableview cell to fill the cell from bottom to top using How to populate UITableView from the bottom upwards? post.

But I want to transform the swipe to Delete option as well. Please refer the image for more detail.

enter image description here

You can see the Delete option is not transform as the tableview. Any helpful answer will be very appreciated.

Shiv Jaiswal
  • 539
  • 1
  • 6
  • 22
Gautam Sareriya
  • 1,833
  • 19
  • 30

2 Answers2

2

First reverse UITableView in viewDidLoad

override func viewDidLoad() {
        super.viewDidLoad()
        tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
}

Then reverse the cell in cellForRowAt.

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            guard let cell = tableView.dequeueReusableCell(withIdentifier: "MyTableViewCell", for: indexPath) as? MyTableViewCell else { fatalError() }

            cell.transform = CGAffineTransform(scaleX: 1, y: -1)
            cell.contentView.transform = CGAffineTransform(scaleX: 1, y: -1)

            return cell
        }
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let delete = UITableViewRowAction(style: .default, title: nil) { (action, indexPath) in
            // delete item at indexPath
        }

        let label = UILabel(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 75, height: tableView.rectForRow(at: indexPath).height)))
        label.numberOfLines = 0
        label.textAlignment = .center
        label.textColor = UIColor.white
        label.backgroundColor = UIColor.red
        label.text = "Delete"
        UIGraphicsBeginImageContextWithOptions(label.bounds.size, false, 0.0)
        label.layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()



        if let cgImage = image?.cgImage {
            let rotada3 = UIImage(cgImage: cgImage, scale: image!.scale, orientation: .downMirrored)
            delete.backgroundColor = UIColor(patternImage: rotada3)

        }


        return [delete]
    }

Here on editActionsForRowAt I did a work around to print image with mirrored text

Same7Farouk
  • 837
  • 9
  • 19
  • I tried with the same as per your code but didn't work it. Please check this image https://imgur.com/2kOWkDr – Gautam Sareriya Nov 26 '19 at 14:23
  • @GautamSareriya, I have tested it now it is working – Same7Farouk Nov 26 '19 at 15:50
  • 1
    just one small correction in cellForRowAt method to transform the cell, use only cell.contentView.transform = CGAffineTransform(scaleX: 1, y: -1) and rest of the code will be same. And it will work. Thanks :) – Gautam Sareriya Nov 27 '19 at 05:27
  • I've corrected the mistake, Please mark it as correct answer to let other knows – Same7Farouk Nov 27 '19 at 06:25
  • it's working only for 1 to 3 line of message cell. But if the message cell increase more than 3 line then it will not working. Please check the image https://imgur.com/BIxPElG. – Gautam Sareriya Nov 27 '19 at 08:10
  • You can change the height of the label to be equals cell. You have the index so call tableview.rectForRow(at: IndexPath) – Same7Farouk Nov 27 '19 at 08:32
0

Transform tableview

tableView.transform = CGAffineTransform(rotationAngle: -(.pi))

Then within cell

cell.transform = CGAffineTransform(rotationAngle: .pi)
Gowri G
  • 420
  • 4
  • 18