Добавление UIActivityindicatorView в UIAlertView - PullRequest
15 голосов
/ 02 июня 2009

Я хочу создать UIAlertView, который скажет, что "... в процессе". Это также покажет, что UIActivityindicatorView на нем. Не могли бы вы дать мне знать, как я могу это сделать?

Спасибо.

Ответы [ 3 ]

41 голосов
/ 03 июня 2009

Это довольно просто. Просто создайте UIActivityIndicatorView и добавьте его в качестве подпредставления в 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];
2 голосов
/ 23 августа 2013

В моем случае я обнаружил, что с использованием жестко закодированных рамок это плохо. И если в моем сообщении больше одной строки, индикатор показывает верхнюю часть моего сообщения.

Так что я создаю функцию с индикатором макета, если размер 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;
}

В этом случае индикатор всегда по центру

Однострочное сообщение:

enter image description here

Еще одно сообщение:

enter image description here

0 голосов
/ 16 июля 2013
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];

Этот прядильщик скрывается при закрытии AlertView.

[alert dismissWithClickedButtonIndex:0 animated:YES];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...