2016-08-13 3 views
1

Ich muss den Aktivitätsindikator mit der Unschärfe Overlay-Hintergrund in Ziel c.Wie das tun.wie man Overlay mit Aktivitätsanzeige programmatisch machen

Ich habe diesen Code versucht, aber nicht in der Lage, Overlay für view.Note, dass ich nur View-Controller mit einer Taste haben.Nach Drücken dieser Taste muss ich ein Overlay mit der Aktivitätsanzeige machen.

spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 225, 20, 30)]; 
    [spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; 
    spinner.center = CGPointMake([[UIScreen mainScreen]bounds].size.width/2, [[UIScreen mainScreen]bounds].size.height/2); 
    spinner.color = [UIColor redColor]; 
    [self.view addSubview:spinner]; 

Wie geht das ??

+0

diese Bibliothek Versuchen Sie stattdessen, https://github.com/SVProgressHUD/SVProgressHUD – Harsh

+0

I sollte keine Bibliothek von Drittanbietern verwenden – mack

+0

eine Überlagerung machen oder eine Unschärfe backgound für viewcontroler machen – mack

Antwort

0

Das habe ich in einem meiner Projekte schon lange gemacht. :)

Tag der Ansicht:

#define TAG_BGVIEW 182 


/* 
********************************************************* 
This method creates the activity alert on the view and 
sets its center to the center of the specified view 
********************************************************* 
*/ 
+ (void)showActivityIndicatorOnView:(UIView*)view withCenter:(CGRect)frame withText:(NSString*)text { 

    [view setUserInteractionEnabled:NO]; 


    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(10, frame.size.height/2 -70, 300, 170)]; 
    backgroundView.tag = TAG_BGVIEW; 
    [backgroundView.layer setCornerRadius:5.0f]; 
    [backgroundView.layer setBorderWidth:2.0f]; 
    [backgroundView.layer setBorderColor:[UIColor blackColor].CGColor]; 
    [backgroundView setBackgroundColor:[UIColor blackColor]]; 
    [backgroundView setAlpha:0.8f]; 

    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    [spinner startAnimating]; 
    spinner.center = CGPointMake(backgroundView.frame.size.width/2, backgroundView.frame.size.height/2); 


    UILabel *indicatorLabel = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width/2, frame.size.height/2 + spinner.frame.size.height + 15, 300, 40)]; 
    [indicatorLabel setText:text]; 
    [indicatorLabel setTextAlignment:NSTextAlignmentCenter]; 
    [indicatorLabel setNumberOfLines:0]; 
    [indicatorLabel setFont:[AppStyle getTableViewCellFont]]; 
    [indicatorLabel setTextColor:[UIColor whiteColor]]; 
    indicatorLabel.center = CGPointMake(backgroundView.frame.size.width/2, backgroundView.frame.size.height/2 + spinner.frame.size.height + 10); 

    [view addSubview:backgroundView]; 
    [backgroundView addSubview:spinner]; 
    [backgroundView addSubview:indicatorLabel]; 
} 

Dies ist, wie man es stoppen kann:

/* 
********************************************************* 
This method stops the activity indicator visible on 
the screen 
********************************************************* 
*/ 
+ (void)stopActivityIndicatorOnView:(UIView*)view { 

    for (UIView *currentView in view.subviews) { 


     if ([currentView isKindOfClass:[UIView class]]) { 

      UIView *view = (UIView*)currentView; 

      if (view.tag == TAG_BGVIEW) { 
       [view removeFromSuperview]; 
      } 

     } 

    } 

    [view setUserInteractionEnabled:YES]; 
} 
+0

Wie kann ich diese Methode nach dem Drücken der Taste Aktion – mack

+0

Ich muss diese Methode innerhalb aufrufen Meine Tastenaktion – mack

+0

Kopieren Sie diesen Code in eine Ihre .m-Datei. Rufen Sie diese Methode dann mit '[YourClassName stopActivityIndicatorOnView: self.view]' auf – Harsh

Verwandte Themen