How to display activity indicator in middle of the iphone screen?

前端 未结 15 894
盖世英雄少女心
盖世英雄少女心 2020-12-22 22:43

When we draw the image, we want to display the activity indicator. Can anyone help us?

相关标签:
15条回答
  • 2020-12-22 22:50

    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];
    
    0 讨论(0)
  • 2020-12-22 22:51
    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)
    
        }
    }
    
    0 讨论(0)
  • 2020-12-22 22:55
    UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]     
            initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    
        activityView.center=self.view.center;
        [activityView startAnimating];
        [self.view addSubview:activityView];
    
    0 讨论(0)
  • 2020-12-22 22:55

    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/

    0 讨论(0)
  • 2020-12-22 22:55

    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.

    0 讨论(0)
  • 2020-12-22 22:55

    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();
    
    }
    
    0 讨论(0)
提交回复
热议问题