自定義彈出框Alter


原理就是創建一個透明的UIViewController

demo中是重新創建了一個storyboard,里面有一個自定義的UIViewController命名為:EasyAlert

class EasyAlert: UIViewController {
    
    static var ins:EasyAlert!

    override func viewDidLoad() {
        super.viewDidLoad()
        
      
        
    }
    
    static var instance:EasyAlert{
        get{
            if(ins == nil){
                
                 let sb = UIStoryboard(name: "Alert", bundle: nil)
                 ins = sb.instantiateViewControllerWithIdentifier("EasyAlert") as! EasyAlert
                 ins.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
                 ins.modalPresentationStyle = .Custom
                 //inc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
                 ins.modalPresentationStyle = .Custom
                
            }
            return ins
        }
    }
    
    @IBAction func close(sender: AnyObject) {
        
        dismissViewControllerAnimated(true, completion: {
            ()->Void in
            
            
        })
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    
}

  在需要彈出框的時候,啟動創建的storyboard:

  @IBAction func showAlert(sender: AnyObject) {
        
        var alert = EasyAlert.instance
      
       presentViewController(alert, animated: true, completion: nil)
    }

 

效果: 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM