Reputation: 41
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
Reputation: 1822
I have Read your Question :
If I am not Wrong i have done following Setup to support your USE-Case:
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()
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
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