mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-14 22:45:54 +03:00
52 lines
1.8 KiB
Swift
52 lines
1.8 KiB
Swift
// Copyright © 2021 Tokenary. All rights reserved.
|
|
|
|
import UIKit
|
|
|
|
extension UIViewController {
|
|
|
|
var inNavigationController: UINavigationController {
|
|
let navigationController = UINavigationController()
|
|
navigationController.viewControllers = [self]
|
|
return navigationController
|
|
}
|
|
|
|
@objc func dismissAnimated() {
|
|
dismiss(animated: true)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func showPasswordAlert(title: String, message: String?, completion: @escaping ((String) -> Void)) {
|
|
let alert = UIAlertController(title: title, message: message, 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()
|
|
}
|
|
|
|
func endEditingOnTap() -> UITapGestureRecognizer {
|
|
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(endEditing))
|
|
tapGestureRecognizer.cancelsTouchesInView = false
|
|
view.addGestureRecognizer(tapGestureRecognizer)
|
|
return tapGestureRecognizer
|
|
}
|
|
|
|
@objc func endEditing() {
|
|
view.endEditing(true)
|
|
}
|
|
|
|
}
|