Lasse Bickmann
Lasse Bickmann

Reputation: 41

Placing a UIActivityIndicatorView

I have an Activity Indicator and it shows in the middel. How do I place it in the left top corner of the view?

var activityIndicator = UIActivityIndicatorView()

func show() {
             UIApplication.shared.beginIgnoringInteractionEvents()

            self.activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))

            self.activityIndicator.center = self.view.center

            self.activityIndicator.hidesWhenStopped = true

            self.activityIndicator.activityIndicatorViewStyle =  UIActivityIndicatorViewStyle.gray

            self.checkView.addSubview(self.activityIndicator)

            self.activityIndicator.startAnimating()
}

Upvotes: 1

Views: 2712

Answers (2)

Abhirajsinh Thakore
Abhirajsinh Thakore

Reputation: 1822

I have Read your Question :

If I am not Wrong i have done following Setup to support your USE-Case:

  1. I have used the already available view for showing the Loader i.e. Main View.
  2. Now I have implemented the following code to set Activity Indicator at top left corner in viewDidLoad You Can use in function also.

    self.activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
    self.activityIndicator.hidesWhenStopped = true
    self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
    self.checkView.addSubview(self.activityIndicator)
    self.activityIndicator.startAnimating()
    
  3. Dont Forget to add var activityIndicator = UIActivityIndicatorView() at the Top and also Make Sure there are no colour combination Issues.

Following all this steps Perfectly , I am Getting an Activity Indicator at Top Left of my Main View.

Thanks

Upvotes: 1

The iOSDev
The iOSDev

Reputation: 5267

The issue is the added UIActivityIndicatorView's center needs to be set properly. Just change the self.activityIndicator.center = self.view.center line to self.activityIndicator.center = CGPoint(x: 0, y: 180)

This will solve your issue.

Note: You can set value if y to any value you want.

Upvotes: 0

Related Questions