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()
}
}
答案 0 :(得分:0)
我猜你的mySpinner
ivar没有被正确保留或宣布。
在.h文件中,将其声明为属性。那就是:
@property (strong) UIActivityIndicatorView *mySpinner;
然后,当你创建它时:
self.mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
当您在按钮单击方法中引用它时:
[self.mySpinner startAnimating];