Saturday, 7 June 2014

Custom activityIndicator using objective C

-(void)StartProgressBar:(NSString *)strMessgae superView:(UIView *)view
{
    
    UIView *alertView=[[UIView alloc] initWithFrame:CGRectMake((view.frame.size.width/2)-50, (view.frame.size.height/2)-80, 100, 70)];
    alertView.tag=505;
    [alertView setBackgroundColor:[UIColor blackColor]];
    [alertView setAlpha:.7];
    alertView.layer.cornerRadius=8.0f;
    
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    //[activityIndicator setFrame:CGRectMake((alertView.frame.size.width/2)-25, 10, 55, 30)]; // Commented on 28thJan2014
    [activityIndicator setFrame:CGRectMake((alertView.frame.size.width/2)-25, 20, 55, 30)];
    [activityIndicator startAnimating];
    [alertView addSubview:activityIndicator];
    
    // Commented on 28thJan2014 START --
//    UILabel *lbl=[[UILabel alloc] initWithFrame:CGRectMake(0, 40, alertView.frame.size.width, 30)];
//    lbl.text=strMessgae;
//    [lbl setBackgroundColor:[UIColor clearColor]];
//    [lbl setTextColor:[UIColor whiteColor]];
//    [lbl setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
//    [lbl setTextAlignment:NSTextAlignmentCenter];
//    [alertView addSubview:lbl];
    // -- END
    
    view.userInteractionEnabled = NO;
    self.navigationController.view.userInteractionEnabled = NO;
    [view addSubview:alertView];
    
    
}

-(void)StopProgressBar:(UIView *)view
{
    //[alertProgressBar dismissWithClickedButtonIndex:0 animated:YES];
    UIView *subView=(UIView *)[view viewWithTag:505];
    
    if (subView)
        [subView removeFromSuperview];
    
    view.userInteractionEnabled = YES;
    self.navigationController.view.userInteractionEnabled = YES;

}

No comments:

Post a Comment