123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // Extension+UIAlertController.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2018/9/13.
- // Copyright © 2018年 南鑫林. All rights reserved.
- //
- import UIKit
- extension UIAlertController {
- /// 在指定视图控制器上弹出普通消息提示框2消失
- static func showAlert(title: String, in viewController: UIViewController) {
- let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
- viewController.present(alert, animated: true)
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
- viewController.presentedViewController?.dismiss(animated: false, completion: nil)
- }
- }
-
- ///在根视图控制器上弹出普通消息提示框2s消失
- static func showAlert(title: String) {
- if let vc = UIApplication.shared.keyWindow?.rootViewController {
- showAlert(title: title, in: vc)
- }
- }
-
- ///在指定视图控制器上弹出普通消息提示框
- static func showAlert(message: String, in viewController: UIViewController) {
- let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "确定", style: .cancel))
- viewController.present(alert, animated: true)
- }
-
- ///在根视图控制器上弹出普通消息提示框
- static func showAlert(message: String) {
- if let vc = UIApplication.shared.keyWindow?.rootViewController {
- showAlert(message: message, in: vc)
- }
- }
-
- ///在指定视图控制器上弹出确认框
- static func showConfirm(title:String? = nil, message: String, in viewController: UIViewController,
- confirm: ((UIAlertAction)->Void)?) {
- let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "取消", style: .cancel))
- alert.addAction(UIAlertAction(title: "确定", style: .default, handler: confirm))
- viewController.present(alert, animated: true)
- }
-
- ///在根视图控制器上弹出确认框
- static func showConfirm(title:String? = nil, message: String, confirm: ((UIAlertAction)->Void)?) {
- if let vc = UIApplication.shared.keyWindow?.rootViewController {
- showConfirm(title:title,message: message, in: vc, confirm: confirm)
- }
- }
- /// 调用相机相册
- ///
- /// - Parameters:
- /// - camera: 相机
- /// - album: 相册
- static func showConfirmActionSheet(camera: ((UIAlertAction)->Void)?,album: ((UIAlertAction)->Void)?) {
- let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
- let cancelAction = UIAlertAction(title: "取消", style: .cancel)
- cancelAction.setValue(kThemeColor, forKey: "titleTextColor")
- alert.addAction(cancelAction)
- let cameraAction = UIAlertAction(title: "拍照", style: .default, handler: camera)
- cameraAction.setValue(kThemeColor, forKey: "titleTextColor")
- alert.addAction(cameraAction)
- let albumAction = UIAlertAction(title: "从手机相册选取", style: .default, handler: album)
- albumAction.setValue(kThemeColor, forKey: "titleTextColor")
- alert.addAction(albumAction)
- let viewController = getCurrentVC()
- viewController?.present(alert, animated: true)
- }
- }
|