When we draw the image, we want to display the activity indicator. Can anyone help us?
Hope this will work:
// create activity indicator
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 20.0f, 20.0f)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
...
[self.view addSubview:activityIndicator];
// release it
[activityIndicator release];
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textLbl: UILabel!
var containerView = UIView()
var loadingView = UIView()
var activityIndicator = UIActivityIndicatorView()
override func viewDidLoad() {
super.viewDidLoad()
let _ = Timer.scheduledTimer(withTimeInterval: 10, repeats: false) { (_) in
self.textLbl.text = "Stop ActivitiIndicator"
self.activityIndicator.stopAnimating()
self.containerView.removeFromSuperview()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func palyClicked(sender: AnyObject){
containerView.frame = self.view.frame
containerView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 0.3)
self.view.addSubview(containerView)
loadingView.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
loadingView.center = self.view.center
loadingView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 0.5)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10
containerView.addSubview(loadingView)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
activityIndicator.center = CGPoint(x:loadingView.frame.size.width / 2, y:loadingView.frame.size.height / 2);
activityIndicator.startAnimating()
loadingView.addSubview(activityIndicator)
}
}
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
[self.view addSubview:activityView];
If you want to add a text along with activity indicator please look at http://nullpointr.wordpress.com/2012/02/27/ios-dev-custom-activityindicatorview/
If you want to try to do it by using interface, you can view my video for this. This way, you no need to write any code to show Activity Indicator in the middle of the iPhone screen.
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();
}