You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.6 KiB

4 years ago
4 years ago
  1. //
  2. // ActionSheetHelper.swift
  3. // GME Remit
  4. //
  5. // Created by Amrit Giri on 6/30/20.
  6. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. struct ActionSheetElement {
  10. var title:String = ""
  11. var id:String = ""
  12. var icon: String = ""
  13. }
  14. class ActionSheetHelper: NSObject {
  15. static let shared = ActionSheetHelper()
  16. // Initialization
  17. override init() {
  18. super.init()
  19. }
  20. func openWith(parentVc: UIViewController?, button: UIBarButtonItem?, title: String = "", values: [ActionSheetElement], _ completionHandler: @escaping (_ item: ActionSheetElement) -> Void){
  21. let alertView = UIAlertController(title: title, message: "", preferredStyle: UIAlertController.Style.actionSheet)
  22. alertView.popoverPresentationController?.barButtonItem = button
  23. let cancel = UIAlertAction(title: "cancel_text".localized(), style: UIAlertAction.Style.cancel, handler: nil)
  24. cancel.setValue(UIColor.themeRed, forKey: "titleTextColor")
  25. for each in values{
  26. let action = UIAlertAction(title: each.title, style: UIAlertAction.Style.default) { (click) in
  27. completionHandler(each)
  28. }
  29. action.setValue(UIColor.themeBlue, forKey: "titleTextColor")
  30. let image = UIImage(named: each.icon)?.withRenderingMode(.alwaysOriginal)
  31. action.setValue(image, forKey: "image")
  32. alertView.addAction(action)
  33. }
  34. alertView.addAction(cancel)
  35. parentVc?.present(alertView, animated: true, completion: nil)
  36. }
  37. func open(parentVc: UIViewController?, title: String = "", values: [ActionSheetElement], _ completionHandler: @escaping (_ item: ActionSheetElement) -> Void){
  38. let alertView = UIAlertController(title: title, message: "", preferredStyle: UIAlertController.Style.actionSheet)
  39. let cancel = UIAlertAction(title: "cancel_text".localized(), style: UIAlertAction.Style.cancel, handler: nil)
  40. cancel.setValue(UIColor.themeRed, forKey: "titleTextColor")
  41. for each in values{
  42. let action = UIAlertAction(title: each.title, style: UIAlertAction.Style.default) { (click) in
  43. completionHandler(each)
  44. }
  45. action.setValue(UIColor.themeBlue, forKey: "titleTextColor")
  46. let image = UIImage(named: each.icon)?.withRenderingMode(.alwaysOriginal)
  47. action.setValue(image, forKey: "image")
  48. alertView.addAction(action)
  49. }
  50. alertView.addAction(cancel)
  51. parentVc?.present(alertView, animated: true, completion: nil)
  52. }
  53. }