//
|
// YYAlertOKViewController.swift
|
// WashCar
|
//
|
// Created by alvin_y on 2020/7/9.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
typealias onDoneBlock = () -> Void
|
|
class YYAlertOKViewController: YYViewController {
|
@IBOutlet weak var topConstraint: NSLayoutConstraint!
|
|
/// 分割线
|
@IBOutlet weak var view_line: UIView!
|
|
/// 关闭
|
@IBOutlet weak var button_close: UIButton!
|
|
/// 标题
|
@IBOutlet weak var label_title: UILabel!
|
|
/// 内容
|
@IBOutlet weak var label_content: UILabel!
|
|
/// 确定
|
@IBOutlet weak var button_done: YYButton!
|
|
var alertTitle: String?
|
var textFieldText: String?
|
var alertDoneTitle: String?
|
var isAutoDismiss: Bool = true
|
var isCustom = false
|
|
var onDone: onDoneBlock?
|
|
init (){
|
super.init(nibName: String(describing: YYAlertOKViewController.self), bundle: Bundle.main)
|
|
modalTransitionStyle = .crossDissolve
|
modalPresentationStyle = .overFullScreen
|
|
|
}
|
|
class func display(title: String?, text: String?, doneTitle: String?, isAutoDismiss: Bool = true,onDone: @escaping () -> Void) {
|
let vc = YYAlertOKViewController()
|
vc.alertTitle = title
|
vc.textFieldText = text
|
vc.alertDoneTitle = doneTitle
|
vc.isAutoDismiss = isAutoDismiss
|
vc.onDone = onDone
|
self.base()?.present(vc, animated: true, completion: nil)
|
}
|
|
class func display(text: String?, doneTitle: String?,onDone: @escaping () -> Void) {
|
let vc = YYAlertOKViewController()
|
vc.textFieldText = text
|
vc.alertDoneTitle = doneTitle
|
vc.onDone = onDone
|
vc.isCustom = true
|
self.base()?.present(vc, animated: true, completion: nil)
|
}
|
|
required init?(coder aDecoder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
view.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.7)
|
label_title.text = alertTitle
|
label_content.text = textFieldText
|
button_done.setTitle(alertDoneTitle, for: .normal)
|
if isCustom{
|
button_done.setBackgroundImage(nil, for: .normal)
|
button_done.setTitleColor(#colorLiteral(red: 0.9450980392, green: 0.2117647059, blue: 0.1960784314, alpha: 1), for: .normal)
|
button_close.isHidden = true
|
view_line.isHidden = false
|
topConstraint.constant = 12
|
}
|
}
|
|
@IBAction func didPressDoneButton(_ sender: UIButton) {
|
if isAutoDismiss {
|
dismiss(animated: true) { [unowned self] in
|
self.onDone?()
|
}
|
} else {
|
onDone?()
|
}
|
|
}
|
@IBAction func didPressCloseButton(_ sender: UIButton) {
|
dismiss(animated: true, completion: nil)
|
}
|
}
|