UIAlertController + Extension for UIView customization,

Source: Internet
Author: User

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 )}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.