NVActivityIndicatorView only for particular view

Viewed 8202

I am using this library https://github.com/ninjaprox/NVActivityIndicatorView for showing the loading indicator. By default it blocks the entire view controller but how can I show the activity indicator only for the particular view. For example if a view controller contains a webview and some other view, the activity indicator should be only for the webview and I should be able interact with the other view.

class FaqViewController: UIViewController, UIWebViewDelegate
{

    @IBOutlet var faqWebView: UIWebView!
    static let activityData = ActivityData()
    var activityIndicator : NVActivityIndicatorView!

    override func viewDidLoad()
    {
        super.viewDidLoad()
        faqWebView.delegate = self
        faqWebView.loadRequest(URLRequest(url: URL(string: "https://www.google.com")!))
    }

    func webViewDidStartLoad(_ webView: UIWebView)
    {
        NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE = CGSize(width: 45, height: 45)
        NVActivityIndicatorPresenter.sharedInstance.startAnimating(FaqViewController.activityData)
    }

    func webViewDidFinishLoad(_ webView: UIWebView)
    {
        NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
    }
}
2 Answers

You have to add it as a subView for the what ever the view you want to show it on. In you case you want to show only on UIWebView, then your code should look like

self.faqWebView.addSubView(activityIndicator)

Related