Create Loading View in Objective C

today we are doing how to create Loading View in objective C .

Purpose Of Loading view

if you are request for calling Web-services then it takes a time to get response. So what to do until not getting response ??? yes stop user interaction in whole screen until not get web-service response.!!

Create Loading View

create one view with the size of window with clear color and add sub view with whatever you like to display loading view to user (NoT: Set view with Stop user Interaction while you are displaying Loading View )

method for Show Loading view To user

-(void)showLoadingView
{
    
    if (loadView == nil) {
		loadView = [[UIView alloc] initWithFrame:self.window.frame];
        loadView.opaque = NO;
        loadView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.3];
        
        CGRect windowFrm =self.window.frame;
        
        viewBack = [[UIView alloc] initWithFrame:CGRectMake(windowFrm.size.width/2 -65 , windowFrm.size.height/2 -20, 130, 40)];
        viewBack.backgroundColor = [UIColor blackColor];
        viewBack.alpha = 0.7f;
        viewBack.tag = 999;
        viewBack.layer.masksToBounds = NO;
        viewBack.layer.cornerRadius = 2;
        
        spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 10.0, 20.0, 20.0)];
        spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [spinningWheel startAnimating];
        [viewBack addSubview:spinningWheel];
        
        UILabel *lblLoading = [[UILabel alloc] initWithFrame:CGRectMake(23, 5, 100, 25)];
        lblLoading.text = @"Loading...";
        lblLoading.backgroundColor = [UIColor clearColor];
        lblLoading.font = [UIFont systemFontOfSize:17.0f];
        lblLoading.textAlignment = NSTextAlignmentCenter;
        lblLoading.textColor = [UIColor whiteColor];
        
        [viewBack addSubview:lblLoading];
        [loadView addSubview:viewBack];
    }
    [self.window addSubview:loadView];
}

method for Hide Loading View from the screen

-(void)hideLoadingView
{
    [loadView removeFromSuperview];
    loadView = nil;
}


Preview Screen while Loading

iOS Simulator Screen shot 05-Oct-2014 1.46.12 pm

you can download demo programs From here

you can download demo programs From here