2009-06-02 13 views

Respuesta

41

Es bastante simple. Simplemente cree un UIActivityIndicatorView y agréguelo como una subvista al UIAlertView.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" " message:@" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)]; 
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 
    [alert addSubview:progress]; 
    [progress startAnimating]; 

    [alert show]; 
+0

Gracias, funcionó. – ebaccount

+0

Es una gran respuesta, pero me pregunto ¿cómo puedo descartarla de la vista si no hay un botón? –

+4

[alert dismissWithClickedButtonIndex: 0 animated: YES]; –

0
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
spinner.center = CGRectMake(xcords, ycords, width, height); 
[alert addSubview:spinner]; 
[spinner startanimating]; 
[alert show]; 

Este spinner se oculta en despedir de AlertView.

[alert dismissWithClickedButtonIndex:0 animated:YES]; 
2

En mi caso, encontré que usar orígenes de marcos impresos es malo. Y si mi mensaje tiene más una línea, el indicador muestra la parte superior de mi mensaje.

lo tanto, crear la función con indicador de maquetación si el tamaño UIAlertView

+(UIAlertView*) progressAlertWithTitle:(NSString*) title andMessage:(NSString*) message andDelegate:(id)delegate{ 
    UIAlertView *progressAlert = [[UIAlertView alloc] init]; 
    [progressAlert setTitle:title]; 
    [progressAlert setMessage:message]; 
    [progressAlert setDelegate:delegate]; 
    UIActivityIndicatorView *progress=nil; 
    progress= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    [progressAlert addSubview:progress]; 
    [progress startAnimating]; 

    [progressAlert show]; 

    progress.frame=CGRectMake(progressAlert.frame.size.width/2-progress.frame.size.width, progressAlert.frame.size.height-progress.frame.size.height*2, progress.frame.size.width, progress.frame.size.height); 


    return progressAlert; 
} 

En este caso, el indicador siempre por el centro de

Una línea mensaje:

enter image description here

Más mensaje de una línea:

enter image description here

Cuestiones relacionadas