I have a login screen on my iOS app. When I click login button I want to make sure that user should be displayed a loading image in center of the screen.
I found lots of different methods online but I am after a simplest method. I found a way to display activity Indicator with minimum code:
First of all, import your UI Kit:
import UIKit;
Then you have to initiate activity indicator:
let activityIndicator:UIActivityIndicatorView = UIActivityIndicatorView();
Then just copy paste this functions below which are self explainatory and call them whereever you need them:
func startLoading(){
activityIndicator.center = self.view.center;
activityIndicator.hidesWhenStopped = true;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray;
view.addSubview(activityIndicator);
activityIndicator.startAnimating();
UIApplication.shared.beginIgnoringInteractionEvents();
}
func stopLoading(){
activityIndicator.stopAnimating();
UIApplication.shared.endIgnoringInteractionEvents();
}
Although, I am still not convinced that it's the best way to do it. Could it still be reduced?
Here is how my screen looks with the code: