swiftalert

Add image to actionsheet


How to add screenshot of tableview to first "action" in UIAlertController? I tried to do it like that

let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let action = UIAlertAction(title: NSLocalizedString("Share routine", comment: ""), style: .default, handler: { _ in
})
action.setValue(image, forKey: "image")
actionSheet.addAction(action)
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil))
UIApplication.topViewController()?.present(actionSheet, animated: true, completion: nil)

Solution

  • I tried your code, and found some mistakes

    First of all, instead of image use

    image.withRenderingMode(.alwaysOrigin)
    

    And if you want to place your image to certain position use imageView