IOS:在web视图中添加活动指示器视图

IOS:在web视图中添加活动指示器视图,ios,Ios,我猜你的mySpinnerivar没有被正确地保留或声明 在.h文件中,将其声明为属性。即: class ViewController: UIViewController , UIWebViewDelegate { var webview = UIWebView() var boxView = UIView() @IBAction func webview(sender: UIButton) {

我猜你的
mySpinner
ivar没有被正确地保留或声明

在.h文件中,将其声明为属性。即:

    class ViewController: UIViewController , UIWebViewDelegate {
          var  webview = UIWebView()
          var boxView = UIView()
           @IBAction func webview(sender: UIButton) {
                 let activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)        
                 activityView.frame = CGRect(x: 20, y: 12, width: 40, height: 40)
                 activityView.startAnimating()
                webview.addSubview(activityView)
                webview.reload()
                let url = NSURL(string:"http://www.sugoilabs.com")
                       UIApplication.sharedApplication().openURL(url!)    
                }
                override func viewDidLoad() {
                      super.viewDidLoad()
               // Do any additional setup after loading the view, typically from a nib.
                }
                func webViewDidStartLoad(webView_Pages: UIWebView) {
                      webview.delegate = self
                     // Box config:
                     boxView = UIView(frame: CGRect(x: 115, y: 110, width: 80, height: 80))
                     boxView.backgroundColor = UIColor.blackColor()
                     boxView.alpha = 1
                     boxView.layer.cornerRadius = 10
                    // Spin config:
                    let activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
                    activityView.frame = CGRect(x: 20, y: 12, width: 40, height: 40)
                    activityView.startAnimating()
                   // Text config:
                   let textLabel = UILabel(frame: CGRect(x: 0, y: 50, width: 80, height: 30))
                  textLabel.textColor = UIColor.blackColor()
                  textLabel.textAlignment = .Center
                  textLabel.font = UIFont(name: textLabel.font.fontName, size: 13)
                  textLabel.text = "Loading..."

                  // Activate:
                 boxView.addSubview(activityView)
                 boxView.addSubview(textLabel)
                 self.view.addSubview(boxView)
             }
            func webViewDidFinishLoad(webView_Pages: UIWebView) {
                  // Removes it:
                  boxView.removeFromSuperview()

           }
  }
然后,当您创建它时:

@property (strong) UIActivityIndicatorView *mySpinner;
当您在按钮单击方法中引用它时:

self.mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

请删除这些白线。它很难读!最后,有什么问题吗?
[self.mySpinner startAnimating];