Activity indicator with custom image

后端 未结 10 1269
甜味超标
甜味超标 2021-01-31 05:58

I am loading a UIWebView and in the meantime I wan\'t to show a blank page with this\"spinner\" activity indic

10条回答
  •  抹茶落季
    2021-01-31 06:39

    it works in both SWITF 3 and 4

    var activityIndicator = UIActivityIndicatorView()
    var myView : UIView = UIView()
    
    func viewDidLoad() {
        spinnerCreation()
    }
    
    func spinnerCreation() {
    
        activityIndicator.activityIndicatorViewStyle =  .whiteLarge
    
        let label = UILabel.init(frame: CGRect(x: 5, y: 60, width: 90, height: 20))
        label.textColor = UIColor.white
        label.font = UIFont.boldSystemFont(ofSize: 14.0)
        label.textAlignment = NSTextAlignment.center
        label.text = "Please wait...."
    
        myView.frame = CGRect(x: (UIScreen.main.bounds.size.width - 100)/2, y: (UIScreen.main.bounds.size.height - 100)/2, width: 100, height: 100)
    
        myView.backgroundColor = UIColor.init(white: 0.0, alpha: 0.7)
        myView.layer.cornerRadius = 5
        activityIndicator.center = CGPoint(x: myView.frame.size.width/2, y:  myView.frame.size.height/2 - 10)
        myView.addSubview(activityIndicator)
        myView.addSubview(label)
    
        myView.isHidden = true
        self.window?.addSubview(myView)
    }
    
    @IBAction func activityIndicatorStart(_ sender: Any) {
        myView.isHidden = false
        self.activityIndicator.startAnimating()
        self.view.isUserInteractionEnabled = false
        self.view.bringSubview(toFront: myView)
    }
    
    @IBAction func activityIndicatorStop(_ sender: Any)() {
        myView.isHidden = true
        self.activityIndicator.stopAnimating()
        self.view.isUserInteractionEnabled = true
    }
    

提交回复
热议问题