0

I am newbie on IOS Development. I Created a UIWebView.

When the application launches I implemented the loader.

Now I want the loader to be a little bigger in size with some background image.

My code is this:

    private var loadingObservation: NSKeyValueObservation?

    private lazy var loadingIndicator: UIActivityIndicatorView = {
        let spinner = UIActivityIndicatorView()
        spinner.translatesAutoresizingMaskIntoConstraints = false

        spinner.color = .black

        return spinner
    }()

override func viewDidLoad() {
        super.viewDidLoad()

        loadingObservation = webView.observe(\.isLoading, options: [.new, .old]) { [weak self] (_, change) in
            guard let strongSelf = self else { return }

            // this is fine
            let new = change.newValue!
            let old = change.oldValue!

            if new && !old {
                strongSelf.view.addSubview(strongSelf.loadingIndicator)
                strongSelf.loadingIndicator.startAnimating()
                NSLayoutConstraint.activate([strongSelf.loadingIndicator.centerXAnchor.constraint(equalTo: strongSelf.view.centerXAnchor),
                                             strongSelf.loadingIndicator.centerYAnchor.constraint(equalTo: strongSelf.view.centerYAnchor)])
                strongSelf.view.bringSubviewToFront(strongSelf.loadingIndicator)
            }
            else if !new && old {
                strongSelf.loadingIndicator.stopAnimating()
                strongSelf.loadingIndicator.removeFromSuperview()
            }
        }


        let myURL = URL(string: "http://192.168.1.4:8080")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)


    }

By this code I am getting the result like this:

enter image description here

Is there any expert on IOS who can help me out regarding this.

I want to increase the size of Loader. Any help is really appreciated regarding this. Thanks

Mohmmad S
  • 5,001
  • 4
  • 18
  • 50
Aks
  • 1,092
  • 3
  • 12
  • 29

2 Answers2

7

You can try setting loadingIndicator.transform = CGAffineTransform.init(scaleX: 2, y: 2)

Thanh Vu
  • 1,599
  • 10
  • 14
2

Make extension of UIActivityIndicatorView -

extension UIActivityIndicatorView {
    func scaleIndicator(factor: CGFloat) {
        transform = CGAffineTransform(scaleX: factor, y: factor)
    }
}

Then can access scaleIndicator() method from your UIActivityIndicatorView object anywhere -

activityIndicatorView.scaleIndicator(factor: 2.5)
AGM Tazim
  • 2,213
  • 3
  • 16
  • 25