0

I want to add an activity indicator inside the message , the uiAlert message, i tried basically everything on the internet, and nothing worked for me, i will just have the uialertview alone , here's my code

UIAlertView  *waitAlert = [[UIAlertView alloc] initWithTitle:@"Please Wait...." message:@"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
progress.color = [UIColor blackColor];
[waitAlert addSubview: progress];
[progress startAnimating];
[waitAlert show];

This is what i end up having
enter image description here

what am i missing!?

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Elias Rahme
  • 2,226
  • 3
  • 28
  • 53
  • Why not use [MBProgressHud](https://github.com/jdg/MBProgressHUD)… its a pretty neat library for loaders and very simple to use... – Ahmed Z. Apr 15 '14 at 09:45
  • 2
    With `iOS7`, you can't add subview to `UIAlertView`. You'll have to do your own AlertView, or use one available on CocoaControls/GitHub. – Larme Apr 15 '14 at 09:46
  • possible duplicate of [Alert view is showing white rectangle in iOS7](http://stackoverflow.com/questions/18895106/alert-view-is-showing-white-rectangle-in-ios7) – Amar Apr 15 '14 at 09:54
  • See also: http://stackoverflow.com/questions/18729220/uialertview-addsubview-in-ios7?lq=1 – Amar Apr 15 '14 at 09:54
  • You can add subview on UIAlertView but subviews are not shown. You can check it's subview count property. – Anand Suthar Apr 15 '14 at 09:58
  • @Larme thank you, you were right, the best way to do so is to create my own alertView, if u please answer the question and i'll post it as the correct one – Elias Rahme Apr 15 '14 at 11:49

2 Answers2

1

in iOS 7 you cannot addSubview anything on UIAlertView,that was possible till iOS 6.1.so MBProgressHud is the best and simple solution for that

Shehbaz Khan
  • 1,892
  • 3
  • 24
  • 31
0

Try to add your UIActivityIndicator using the UIAlertViewDelegate method:

- (void)didPresentAlertView:(UIAlertView *)alertView
{
    UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    progress.frame = CGRectMake(125, 50, 30, 30);

    [progress startAnimating];
    [alertView addSubview:progress];
}
etolstoy
  • 1,798
  • 21
  • 33