Adding UIActivityIndicatorView to UIAlertView - ios

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
what am i missing!?

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

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];
}

Related

UIAlertView loading indicator is almost offside?

I have following code:
_loadingAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_LOADING
message:ALERT_MESSAGE_LOADING
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];
[_loadingAlert setValue:indicator forKey:#"accessoryView"];
[_loadingAlert show];
Result:
My purpose is to display an alertview with loading indicator inside but the result is as attached screenshot. Anyone has idea?
Try with this code (as suggested by #A-Live), you can adjust the padding value to add more space at the bottom of the activity indicator.
_loadingAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_LOADING
message:ALERT_MESSAGE_LOADING
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
indicator.translatesAutoresizingMaskIntoConstraints = YES;
[indicator startAnimating];
CGFloat padding = 15;
UIView *indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, indicator.frame.size.width, indicator.frame.size.width+padding)];
[indicatorView addSubview:indicator];
[_loadingAlert setValue:indicatorView forKey:#"accessoryView"];
[_loadingAlert show];

How to create UIProgressViewStyleBar on UIAlertview iOS 7?

I am trying to create UIProgressViewStyleBar on UIAlertview with JSON loading status info on my app. Now my problem is I cant see UIProgressViewStylebar on iOS 7. Please help me!
My Source:
UIAlertView *alertss = [[UIAlertView alloc] initWithTitle:#"Please Wait..Downloading reports..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ;
alertss.frame=CGRectMake(50, 50, 280, 40);
UIProgressView *prgView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
prgView.frame = CGRectMake(5, 0, 70, 20);
prgView.hidden=NO;
[alertss addSubview:prgView];
[alertss show];
UILabel *statusLabel = [[UILabel alloc] init];
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.textColor = [UIColor whiteColor];
statusLabel.font = [UIFont fontWithName:#"AmericanTypewriter-Condensed" size:18.0];
statusLabel.frame = CGRectMake(120, 80, 80, 20);
[alertss addSubview:statusLabel];
[alertss show];
Yeah that is the correct code with that code add this line
[progressView setProgress:0.75f animated:YES];
before showing your alert. change the progress value depends on your need. or animate it if you want.
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
UIProgressView* progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[progressView setProgress:0.75f animated:YES];
// you have to set the accessoryView to alertview
[av setValue:progressView forKey:#"accessoryView"];
[av show];
see adding MBprogressHUD is so simple. first download the MBProgressHUD Lib from the GitHub and import in your project as #import "MBProgressHUD.h"
And then simple line to show the progressHUD is as follows :
to show:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
to hide:
[MBProgressHUD hideHUDForView:self.view animated:YES];
for your problem use this code:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[av show];
[MBProgressHUD hideHUDForView:self.view animated:YES];
Here I used the circular loader. if you want to customise it you can use this loader in many forms as you wish.

checkbox in uialertview in ios8

I want to add checkbox exactly as the below image
below is my code:
UIButton *nameField = [[UIButton alloc] initWithFrame:CGRectMake(120, 0, 30, 30.0)];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
[v setBackgroundColor:[UIColor clearColor]];
[nameField setImage:[UIImage imageNamed:#"unchecked.png"] forState:UIControlStateNormal];
[v addSubview:nameField];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Delete selected pods from server?" message:
#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[av setValue:v forKey:#"accessoryView"];
av.message = #"This will delete all the posts related to the pictures you want to delete!";
[av show];
with the above code I am getting as :
I want to get checkbox beside message..
Any help or suggestion how to proceed?
You can use https://github.com/wimagguc/ios-custom-alertview
Create your custom content view and set it like
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
UIView *customView ..; //Your custom view
[alertView setContainerView:customView];
I would suggest you to do not do that.
accessoryView is not a public exposed API and you risk an app rejection
UIAlertView is deprecated in iOS8, use UIAlertController
You can use a third party library, I usually integrate MRProgress in my projects, you can create your own nib and add it.

Add UIActivityIndicatorView to UIActionSheet

I am trying to add an UIActivityIndicatorView to UIActionsSheet in this way:
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:sharedInstance
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for(NSMutableDictionary *dict in moreStructure)
{
NSString *value = [dict valueForKey:TITLE_PARAMETER];
[actionSheet addButtonWithTitle:value];
}
[actionSheet addButtonWithTitle:#"Cancel"];
actionSheet.cancelButtonIndex = [moreStructure count];
[actionSheet showInView:((SectionViewController *)sharedInstance.currentViewController).view];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityView.frame = CGRectMake(100, 500, 15, 15);
[activityView startAnimating];
[actionSheet addSubview:activityView];
When the UIActionSheet appears, however, I do not see an UIActivityIndicatorView on it. Please, help me.
I have try this and this is working... Please check frame of activityView... because its y is 500...
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:nil
cancelButtonTitle:#"Test"
destructiveButtonTitle:#"Test"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityView.frame = CGRectMake(100, 5, 15, 15);
[activityView startAnimating];
[actionSheet addSubview:activityView];
activityView.backgroundColor = [UIColor redColor];
actionSheet.backgroundColor = [UIColor greenColor];
activityView.frame = CGRectMake(100, 500, 15, 15);
// this so this above must change
activityView.frame = CGRectMake(10, 50, 300, 400);

iPhone - AlertView text field shifts using iOS6 [duplicate]

This question already has answers here:
UIAlertView with textfield and three buttons issue in ios 6
(4 answers)
Closed 9 years ago.
I have a problem with my UIAlertView text field using iOS6.
The text field shifts all the way to the top. When i use iOS7, the text field is in the right spot.
Can someone help me? Here is the code:
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Item?"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Add another", #"Done",nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeWords;
[message show];
The text field appears on the title text (here: Item?)
did you try this :
-(void)willPresentAlertView:(UIAlertView *)alertView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
{
[alertView setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alertView subviews];
UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
[message setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
[cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
[savebutton setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
[saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
[textfield setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
Actually this can be fixed manually by detecting the system version. Here is the right way to do this in this post
Try this code, it will work.
- (IBAction)showAlert:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title = #"Item?";
alertView.message = nil;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView addButtonWithTitle:#"Cancel"];
[alertView addButtonWithTitle:#"Add another"];
[alertView addButtonWithTitle:#"Done"];
[alertView show];
}

Resources