zoukankan      html  css  js  c++  java
  • 自定义弹出框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)
        }
    

    效果: 

     

    I am not doing shit today !
  • 相关阅读:
    IDEA Inspections详解
    IDEA 阿里编码规范插件
    IDEA Save Actions插件
    IDEA Lombok插件
    设计模式-简单工厂模式与工厂模式
    DAO设计模式
    Jcrop+strut2+jsp实现图片剪切
    Spring的Bean的作用域
    Spring的事务机制
    windows 下 Redis 主从 读写分离
  • 原文地址:https://www.cnblogs.com/mogul/p/5145140.html
Copyright © 2011-2022 走看看