// // ActionSheetHelper.swift // GME Remit // // Created by Amrit Giri on 6/30/20. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit struct ActionSheetElement { var title:String = "" var id:String = "" var icon: String = "" } class ActionSheetHelper: NSObject { static let shared = ActionSheetHelper() // Initialization override init() { super.init() } func openWith(parentVc: UIViewController?, button: UIBarButtonItem?, title: String = "", values: [ActionSheetElement], _ completionHandler: @escaping (_ item: ActionSheetElement) -> Void){ let alertView = UIAlertController(title: title, message: "", preferredStyle: UIAlertController.Style.actionSheet) alertView.popoverPresentationController?.barButtonItem = button let cancel = UIAlertAction(title: "cancel_text".localized(), style: UIAlertAction.Style.cancel, handler: nil) cancel.setValue(UIColor.themeRed, forKey: "titleTextColor") for each in values{ let action = UIAlertAction(title: each.title, style: UIAlertAction.Style.default) { (click) in completionHandler(each) } action.setValue(UIColor.themeBlue, forKey: "titleTextColor") let image = UIImage(named: each.icon)?.withRenderingMode(.alwaysOriginal) action.setValue(image, forKey: "image") alertView.addAction(action) } alertView.addAction(cancel) parentVc?.present(alertView, animated: true, completion: nil) } func open(parentVc: UIViewController?, title: String = "", values: [ActionSheetElement], _ completionHandler: @escaping (_ item: ActionSheetElement) -> Void){ let alertView = UIAlertController(title: title, message: "", preferredStyle: UIAlertController.Style.actionSheet) let cancel = UIAlertAction(title: "cancel_text".localized(), style: UIAlertAction.Style.cancel, handler: nil) cancel.setValue(UIColor.themeRed, forKey: "titleTextColor") for each in values{ let action = UIAlertAction(title: each.title, style: UIAlertAction.Style.default) { (click) in completionHandler(each) } action.setValue(UIColor.themeBlue, forKey: "titleTextColor") let image = UIImage(named: each.icon)?.withRenderingMode(.alwaysOriginal) action.setValue(image, forKey: "image") alertView.addAction(action) } alertView.addAction(cancel) parentVc?.present(alertView, animated: true, completion: nil) } }