tokenary/Tokenary iOS/Extensions/UIViewController.swift

41 lines
1.4 KiB
Swift
Raw Normal View History

2021-12-06 19:16:03 +03:00
// Copyright © 2021 Tokenary. All rights reserved.
import UIKit
extension UIViewController {
var inNavigationController: UINavigationController {
let navigationController = UINavigationController()
navigationController.viewControllers = [self]
return navigationController
}
2021-12-07 20:35:14 +03:00
@objc func dismissAnimated() {
dismiss(animated: true)
}
2021-12-09 15:09:11 +03:00
func showMessageAlert(text: String) {
let alert = UIAlertController(title: text, message: nil, preferredStyle: .alert)
let okAction = UIAlertAction.init(title: Strings.ok, style: .default)
alert.addAction(okAction)
present(alert, animated: true)
}
2021-12-10 17:21:31 +03:00
func showPasswordAlert(title: String, completion: @escaping ((String) -> Void)) {
let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
alert.addTextField { textField in
textField.isSecureTextEntry = true
textField.textContentType = .oneTimeCode
}
let okAction = UIAlertAction(title: Strings.ok, style: .default) { [weak alert] _ in
completion(alert?.textFields?.first?.text ?? "")
}
let cancelAction = UIAlertAction(title: Strings.cancel, style: .cancel)
alert.addAction(okAction)
alert.addAction(cancelAction)
present(alert, animated: true)
alert.textFields?.first?.becomeFirstResponder()
}
2021-12-06 19:16:03 +03:00
}