UIAlertController + Extension for UIView customization,
UIAlertController + Extension for UIView Customization
Instructions for use
//// ViewController. swift // Alert_Dialog /// Created by Sico2Sico on 02/05/2018. // Copyright (c) 2018 Sico2Sico. all rights reserved. // import UIKitimport Alert_Dialogimport ReactiveSwiftimport reactivecoaimport Resultclass ViewController: UIViewController {override func viewDidLoad () {super. viewDidLoad () self. view. backgroundColor = UIColor. white let newView = UIControl () newView. backgroundColor = UIColor. red let alret = UIAlertController (customView: newView) {(make) in make. size. failed to (300) make. center. equalToSuperview ()} newView. reactive. controlEvents (UIControlEvents. touchUpInside ). observeValues {[weak alret] (view) in print ("handle problem") alret !. Dismiss (animated: true, completion: nil)} alret. show ()}}
Source File
/// UIAlertController + Dialog. swift // AppUIKit /// Created by dezhi on 2018/2/5. // import UIKitimport SnapKitextension UIAlertController {public convenience init (customView: UIView, closure: @ escaping (_ make: ConstraintMaker)-> Void) {self. init (title: nil, message: nil, preferredStyle: UIAlertControllerStyle. alert) view. clipsToBounds = false customView. tag = 1111 view. addSubview (customView) // Add Otherwise, the system reports the following error: let action = UIAlertAction (title: "", style :. default, handler: nil) addAction (action) // constraint customView. snp. makeConstraints {(make) in closure (make)} // hide the System View _ = self. view. subviews. flatMap {(view)-> Void in if view. tag! = 1111 {view. isHidden = true} else {view. isHidden = false} public func show (animated: Bool = true, style: UIBlurEffectStyle? = Nil, completion: ()-> Void )? = Nil) {if let style = style {for subview in view. allSubViewsOf (type: uivisualiztview. self) {subview. effect = UIBlurEffect (style: style)} DispatchQueue. main. async {UIApplication. shared. keyWindow ?. RootViewController ?. Present (self, animated: animated, completion: completion )}}}