How to programmatically add a simple default loading(progress) bar in iphone app

前端 未结 18 2571
你的背包
你的背包 2020-12-12 17:16

I am using http communication in My iPhone app. I want to show a progress bar while it is loading data from server. How can I do it programmatically?

I just want a d

18条回答
  •  悲&欢浪女
    2020-12-12 17:52

    App Delegate.h

    -(void)showLoader;
    
    -(void)hideLoder;
    

    App Delegate.m

    @implementation AppDelegate
    
    AppDelegate *app;
    
    -(void)showLoader
    {
    
        if(loaderView== NULL)
        {
            loaderView=[[UIView alloc] initWithFrame:self.window.frame];
    
            [loaderView setBackgroundColor:[UIColor blackColor]];
    
            [loaderView setAlpha:0.5];
    
            spinner = [[UIActivityIndicatorView alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    
            [loaderView addSubview:spinner];
    
            spinner.center = CGPointMake(loaderView.frame.size.width/2-10, 
    
            loaderView.frame.size.height/2-10);
    
            spinner.hidesWhenStopped = YES;  
        }
        [spinner startAnimating];
        [self.window addSubview:loaderView];
        [self.window bringSubviewToFront:spinner];
        [self.window bringSubviewToFront:loaderView];
    }
    
    -(void)hideLoder
    {       
        if (spinner!= NULL) {           
            [spinner stopAnimating];
        }
    
        [loaderView removeFromSuperview];
    }
    

    now import "AppDelegate.h" class where ever you want to call loader.and you can call the loader like this.

    [app showLoader];

    and

    [app hideLoder];

提交回复
热议问题