iosuitableviewios11uitableviewrowaction

UITableView trailingSwipeActionsConfigurationForRowAt image and title


in iOS 11 we have a feature in UITableView trailingSwipeActionsConfigurationForRowAt to get the swipe events. But when I try to reduce the height of the row the text disappears and only image remains.

Is there any way I can keep both? My cell height should be 60.0 and I need to show both image and title. It works for 84.0. The image size is 30x30 for @2x and 60x60 for @3x

Below is my code

let contextItem = UIContextualAction(style: .normal, title: "Rename") { (contextualAction, view, boolValue) in

       //do something
    }
    contextItem.image = UIImage(named: "deleteIcon")
let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])

Solution

  • It seems there is a bug in iOS 11 that it does not show both image and title at the same time unless the table view cell height is 91 points. for more info you get https://forums.developer.apple.com/thread/86009

    UIContextualAction supports either text or image. By setting the image with setImage: property, basically remove the title when creating the object. If you want both text and image, you need to create images with embedded text.