|
//
// CustomBottomAlertController.swift
// PaiAi
//
// Created by yangbin on 16/4/7.
// Copyright © 2016年 FFIB. All rights reserved.
//
import UIKit
class CustomBottomAlertController: UIViewController {
@IBOutlet weak var contentView: UIView!
@IBOutlet weak var cancelBtn: UIButton!
@IBOutlet weak var confirmBtn: UIButton!
fileprivate var confirmClosure: clickAlertClosure?
fileprivate var cancelClosure: clickAlertClosure?
fileprivate var cancelStr = ""
fileprivate var confirmStr = ""
@IBOutlet weak var confirmHeightConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
initInterface()
showBottomAnimated(animationView: contentView)
}
func initInterface() {
cancelBtn.setTitle(cancelStr, for: .normal)
confirmBtn.setTitle(confirmStr, for: .normal)
confirmClosure.map {_ in confirmBtn.addTarget(self, action: #selector(confirm), for: .touchUpInside)}
if cancelClosure == nil {
confirmHeightConstraint.constant = 48
} else {
if confirmClosure != nil {
confirmHeightConstraint.constant = 48
} else {
confirmHeightConstraint.constant = 0
}
cancelBtn.addTarget(self, action: #selector(cancel), for: .touchUpInside)
}
}
func setInterface(cancelTitle: String, confirmTitle: String, cancel cancelFunction: clickAlertClosure?, confirm confirmFunction: clickAlertClosure?) {
confirmStr = confirmTitle
cancelStr = cancelTitle
cancelClosure = cancelFunction
confirmClosure = confirmFunction
}
@objc func confirm() {
if confirmClosure != nil {
confirmClosure!()
}
dismissBottomAnimated(animationView: contentView)
}
@objc func cancel() {
if cancelClosure != nil {
cancelClosure!()
}
dismissBottomAnimated(animationView: contentView)
}
}
|